From patchwork Tue Aug 4 10:16:53 2026 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kyrylo Tkachov X-Patchwork-Id: 140584 Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from vm01.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 8FE514BA798F for ; Tue, 4 Aug 2026 10:18:08 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 8FE514BA798F Authentication-Results: sourceware.org; dkim=pass (2048-bit key, unprotected) header.d=Nvidia.com header.i=@Nvidia.com header.a=rsa-sha256 header.s=selector2 header.b=HVzoGBz5 X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from CH1PR05CU001.outbound.protection.outlook.com (mail-northcentralusazlp170100001.outbound.protection.outlook.com [IPv6:2a01:111:f403:c105::1]) by sourceware.org (Postfix) with ESMTPS id BDF954BA2E35 for ; Tue, 4 Aug 2026 10:17:27 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org BDF954BA2E35 Authentication-Results: sourceware.org; dmarc=pass (p=reject dis=none) header.from=nvidia.com Authentication-Results: sourceware.org; spf=fail smtp.mailfrom=nvidia.com ARC-Filter: OpenARC Filter v1.0.0 sourceware.org BDF954BA2E35 Authentication-Results: sourceware.org; arc=pass smtp.remote-ip=2a01:111:f403:c105::1 ARC-Seal: i=2; a=rsa-sha256; d=sourceware.org; s=key; t=1785838647; cv=pass; b=vF0u42qFaECXO9EuAaKdOs5YlX1OyRmJVMXCutecRTKxiOYCsgz7BS47T5m5U7ANgyMc8B43RpXMtjgHxxF4hIXiHsYLdk4FAiXEfcNRSbG0HqbcHNQNTd5RJS2zqGLL6sD/QkRQWG/qI9M/In7uZg7BUYZuIWf97UNfRt6xlag= ARC-Message-Signature: i=2; a=rsa-sha256; d=sourceware.org; s=key; t=1785838647; c=relaxed/simple; bh=j3WrBNn1G6FCogpuPRJh+qtAImuilUkeZowZSx1D4XI=; h=DKIM-Signature:From:To:Subject:Date:Message-ID:MIME-Version; b=nUWdrYhfb2Mz4lF+VKFAvalIYsZ2cEfP4NMrpCX+hnftz0UM6MwQCCVziuYqCP7drpE8dBnqrALFpxID2bgQwiO3Ux1F7mpDBzewVMQ+yaom1VXh3jDR6n7L+7dQoJOQzMRgq1gCqb2CW67RJJ1MqWwM6kGDxGysjiZhHwrbZoU= ARC-Authentication-Results: i=2; sourceware.org; dkim=pass (2048-bit key, unprotected) header.d=Nvidia.com header.i=@Nvidia.com header.a=rsa-sha256 header.s=selector2 header.b=HVzoGBz5 DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org BDF954BA2E35 ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=Ta2uqP1woFAcMQr7jaIPOymnUPaHkdmkx8FgMy100jtY6mPsgrh7jBWqfzzAuFEz9eBJTTYllMocOGoO7CoVgHdexv6E6LTOqmAeorLxzuGfzgPqKCWZsP2KgN9oYUKA2PfssDSmbH5CAr+g6yrfttaKW0LqqqcCRCLdY4J1i3oV0J/fiiAUuG0wtH1Nq7XOOTPkhOoPGbF63upowI/OmnTgVBsjTIwWDbejS+2Fe3bxBG5G6c6s9QQsYTTNj+xZk600EPMquulVAjEuJN85pqaL+zl9e35vo06vHqxW2zRJIltiPqDFl9Tx0gsray0V/NgtjVIBfVLbYupFywkcTw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector10001; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=Jwgo9kDZcD4yViYT1yMxiDEI0l29uIgTzASyCPw0Xe0=; b=Eq2JNk4dLHNBdOkVyux7/nzrIXjtZci3nfhnyS34g6+sCgiFQsqA6JBpdZlIEuLNO4AM+r6ZmDkiY4EhxZ0UkxNAN6yX7wM2UqdchBAJVcdgrh1UCfsPfGknFP15cf2V4axWZFuVifHmHySP3WZc3o7EgPnKtlxq++1rmA2BhXWlXVWs4zWJOHBYPs6zrhJqBVGB540JZJe+bitt3vUWrklCy92dQ7B58Z2/3yEmxvq+lmAWG43idFSXQ4xptlUZinIIAZHbfpdgjDJ7y3b17qGOa5kc99lUPFJzZAn2pe078V0/GJT3ap9azWIBJdPzuqsHYbGWQu6yt2JymQClSA== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 216.228.117.161) smtp.rcpttodomain=gcc.gnu.org smtp.mailfrom=nvidia.com; dmarc=pass (p=reject sp=reject pct=100) action=none header.from=nvidia.com; dkim=none (message not signed); arc=none (0) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=Nvidia.com; s=selector2; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=Jwgo9kDZcD4yViYT1yMxiDEI0l29uIgTzASyCPw0Xe0=; b=HVzoGBz5nadZWjUjtRarqbHWAAtUzxm05IeWYoD/9cnhMlPQDLIyeSolh8jHQbbIt8WXbj4ieqWSQFeBKS5Vr5CFR5tSki307UQwX0ieQnhVK2Gl6/7/CYwRfpB3Dna1IqwNd4KD0IXUY71xchKLFLP1gEUc3mFnVNhmeiCpecQuF8LQy4p7zhKFlwZdYwqLipl/AFmTQUBCgqBW0t88eZt1jL88U2byNw9d9Etqf+gZ68EI+bVOT0Zi+CKNTr0UkLKDsumS2ZPi/J03/ZrFd044zqTrka9IBYokbT0RkR8wvNS7KPL51Du23wbSMe00kkB3mQ+CabfLbqOMr0vvPQ== Received: from BN1PR10CA0026.namprd10.prod.outlook.com (2603:10b6:408:e0::31) by SJ0PR12MB6902.namprd12.prod.outlook.com (2603:10b6:a03:484::7) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.21.270.18; Tue, 4 Aug 2026 10:17:19 +0000 Received: from BN1PEPF0000468A.namprd05.prod.outlook.com (2603:10b6:408:e0:cafe::96) by BN1PR10CA0026.outlook.office365.com (2603:10b6:408:e0::31) with Microsoft SMTP Server (version=TLS1_3, cipher=TLS_AES_256_GCM_SHA384) id 15.21.292.15 via Frontend Transport; Tue, 4 Aug 2026 10:17:18 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 216.228.117.161) smtp.mailfrom=nvidia.com; dkim=none (message not signed) header.d=none;dmarc=pass action=none header.from=nvidia.com; Received-SPF: Pass (protection.outlook.com: domain of nvidia.com designates 216.228.117.161 as permitted sender) receiver=protection.outlook.com; client-ip=216.228.117.161; helo=mail.nvidia.com; pr=C Received: from mail.nvidia.com (216.228.117.161) by BN1PEPF0000468A.mail.protection.outlook.com (10.167.243.135) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.21.292.8 via Frontend Transport; Tue, 4 Aug 2026 10:17:18 +0000 Received: from rnnvmail201.nvidia.com (10.129.68.8) by mail.nvidia.com (10.129.200.67) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.2562.20; Tue, 4 Aug 2026 03:17:03 -0700 Received: from ktkachov-mlt.nvidia.com (10.126.230.37) by rnnvmail201.nvidia.com (10.129.68.8) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.2562.20; Tue, 4 Aug 2026 03:17:01 -0700 From: To: CC: Kyrylo Tkachov Subject: [PATCH] match: fold two idioms built from the negation of a value Date: Tue, 4 Aug 2026 12:16:53 +0200 Message-ID: <20260804101653.59834-1-ktkachov@nvidia.com> X-Mailer: git-send-email 2.50.1 MIME-Version: 1.0 X-Originating-IP: [10.126.230.37] X-ClientProxiedBy: rnnvmail203.nvidia.com (10.129.68.9) To rnnvmail201.nvidia.com (10.129.68.8) X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: BN1PEPF0000468A:EE_|SJ0PR12MB6902:EE_ X-MS-Office365-Filtering-Correlation-Id: 9c0d03e7-b5c1-4ff3-41e4-08def2119088 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; ARA:13230040|82310400026|1800799024|376014|36860700016|23010399003|18002099003|11063799006|56012099006|13003099007|6133799003|10067099003; X-Microsoft-Antispam-Message-Info: iTo+gRryRXVVYehek482BQiz+H369f7DDoOu6TXn/0xp9NrYFwbskkFBi4kKWiK2TIAnoz/T6NOWLJO+FWnePPoKOuYuT7r+46hS+EHaOx0X6133afbVA8IzX1Sb5hZEX1B5itZFICiNUtxs1aRaQk/g1kh7jr+SJRKCD112czSUeWjZLiQAzHK8d2SknoT6X22CSKY/OVL4w6xGpF1EXi9fO+Xg7obVDFu2u8FhpAF5ZYdCNY9CREgSI2oeXaBZCQeAdwch7ZE0Pi9hyzaojCJ1DZei1qwQRP6zo8GWuxYnzHR4NK51jJ/lBXTl70s2e0oOUHh0r1WewRdTR36S89s4sEvu9+MxQWmOjNFLk0sdaG4U79nFGVMNSu1KW4o2ZTMIFGFksP78JfIUwQPSnqfcV9zfctmJ6+lTRQWQkB4wSV2RIlzW+wXAX5ew8MgTRFAp1HkXHj3rYwIj8Nb1AFSmZVzhRQO0tCc8kX8l7JieYWLDLXTIzPtXN5Epulj8bruaFnOA/e7tnYLW4Sr5gH8UwUg4pk/D253O0o1Hr5SNfH3HlqCR9G5IXt6+AZ4Xm4ewjvCdJ+KWSz4on6jFaMuTK8saHcIfg3o2Y131UCqg0mZd4492KaNnmi2dXjBUNCeF+/5TO7P6GOUJTG9TdSWm0xnlWXP01fjpPSkRMmVsW98mKjJMLRCy0jLNH7iqaSJlfLc4W6V49+IC0enXwA== X-Forefront-Antispam-Report: CIP:216.228.117.161; CTRY:US; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:mail.nvidia.com; PTR:dc6edge2.nvidia.com; CAT:NONE; SFS:(13230040)(82310400026)(1800799024)(376014)(36860700016)(23010399003)(18002099003)(11063799006)(56012099006)(13003099007)(6133799003)(10067099003); DIR:OUT; SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: G6hrE/fuqvadrwR+phavyRG3u9fD7EVdz1uamsZ4g/MKEAFRYwKubwVFPXs6E9jI9TmgStPzmeXJcAPrYHzP1NpqnIYI0LAaODE89gZ0XsRwRUiRudiEsQKXR+ZYJVpvQtyFBYnXiVMPfNXrSUvkF3uc55S6+/dLR2OT1txijmiwryl1g0pRQuwRRKFhSURBai2pJ5jkIBQBSCfE0mhjxdnq/9NNVXLUVVJLHNvfQwJQC83rYQrorKB3BCrexm0Z8yq3NFIBvZY2c4l+ZMETIPbeDLqloRiOTOvFxUfEvqpyQipwcv+uW90C4wjAV7/ZSqIATSuG4J1oKwOOx9Q9VilofC7NTQsxf6UMP7UviHFfT9LBNtST4d8ywqQEXChMRCMJvSn2GJPd6b+2ASLWl6P9PdeKRPHRfQh2sn0N64usB/QdW9Fra8X3Sj0yxsZS X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 04 Aug 2026 10:17:18.4605 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 9c0d03e7-b5c1-4ff3-41e4-08def2119088 X-MS-Exchange-CrossTenant-Id: 43083d15-7273-40c1-b7db-39efd9ccc17a X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=43083d15-7273-40c1-b7db-39efd9ccc17a; Ip=[216.228.117.161]; Helo=[mail.nvidia.com] X-MS-Exchange-CrossTenant-AuthSource: BN1PEPF0000468A.namprd05.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: SJ0PR12MB6902 X-Spam-Status: No, score=-8.4 required=5.0 tests=BAYES_00, DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, FORGED_SPF_HELO, GIT_PATCH_0, LOCAL_AUTHENTICATION_FAIL_SPF, RCVD_IN_DNSWL_NONE, SPF_HELO_PASS, SPF_NONE, TXREP shortcircuit=no autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on sourceware.org X-BeenThere: gcc-patches@gcc.gnu.org X-Mailman-Version: 2.1.30 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: gcc-patches-bounces~patchwork=sourceware.org@gcc.gnu.org From: Kyrylo Tkachov X | -X has every bit from the lowest set bit of X upwards, so adding X to it clears that bit, and masking with it isolates the padding needed to round X up: X + (X | -X) -> X & (X - 1) X + ((-X) & (C - 1)) -> (X + C - 1) & -C for a power of two C The second is the alignment round up written with the padding computed first, which is how allocators tend to spell it. Neither needs a wrapping type. X - 1 overflows only for the most negative value, where the source already does, and rounding X up is representable exactly when X + C - 1 is, because the largest multiple of C below the maximum leaves room for C - 1. The inclusive or and the conjunction already force an integral type. int f (int x) { return x + ((-x) & 15); } aarch64 -O2: before after neg w1, w0 add w0, w0, 15 and w1, w1, 15 and w0, w0, -16 add w0, w1, w0 The vector spelling folds too, a uniform vector constant is matched with uniform_integer_cst_p. Keep trapping and sanitized negations. Require the consumed padding value to become dead so that the fold cannot add work. Bootstrapped and tested on aarch64-none-linux-gnu. Ok for trunk? Thanks, Kyrill gcc/ChangeLog: * match.pd (X + (X | -X)): New simplification. (X + ((-X) & (C - 1))): Likewise. gcc/testsuite/ChangeLog: * gcc.dg/tree-ssa/signbit-1.c: New test. * gcc.dg/tree-ssa/alignup-2.c: New test. * gcc.dg/tree-ssa/vector-alignup-1.c: New test. * gcc.dg/tree-ssa/alignup-overflow-1.c: New test. * gcc.dg/tree-ssa/alignup-overflow-2.c: New test. Signed-off-by: Kyrylo Tkachov --- gcc/match.pd | 21 ++++++++++++++ gcc/testsuite/gcc.dg/tree-ssa/alignup-2.c | 28 +++++++++++++++++++ .../gcc.dg/tree-ssa/alignup-overflow-1.c | 10 +++++++ .../gcc.dg/tree-ssa/alignup-overflow-2.c | 10 +++++++ gcc/testsuite/gcc.dg/tree-ssa/signbit-1.c | 26 +++++++++++++++++ .../gcc.dg/tree-ssa/vector-alignup-1.c | 15 ++++++++++ 6 files changed, 110 insertions(+) create mode 100644 gcc/testsuite/gcc.dg/tree-ssa/alignup-2.c create mode 100644 gcc/testsuite/gcc.dg/tree-ssa/alignup-overflow-1.c create mode 100644 gcc/testsuite/gcc.dg/tree-ssa/alignup-overflow-2.c create mode 100644 gcc/testsuite/gcc.dg/tree-ssa/signbit-1.c create mode 100644 gcc/testsuite/gcc.dg/tree-ssa/vector-alignup-1.c diff --git a/gcc/match.pd b/gcc/match.pd index 2d172b5f5a0..800864ce9e2 100644 --- a/gcc/match.pd +++ b/gcc/match.pd @@ -2088,6 +2088,27 @@ DEFINE_INT_AND_FLOAT_ROUND_FN (RINT) && !TYPE_OVERFLOW_SANITIZED (type) && !TYPE_OVERFLOW_TRAPS (type)) (maxmin @0 @1)))) +/* X + (X | -X) -> X & (X - 1). X | -X has every bit from the lowest set + bit of X upwards, so adding it clears that bit. */ +(simplify + (plus:c @0 (bit_ior:c@2 @0 (negate @0))) + (if (single_use (@2)) + (bit_and @0 (plus @0 { build_minus_one_cst (type); })))) + +/* X + ((-X) & (C - 1)) -> (X + C - 1) & -C for a power of two C, the + round up to a multiple of C written with the padding computed first. */ +(simplify + (plus:c @0 (bit_and:c@2 (negate @0) uniform_integer_cst_p@1)) + (with { tree cst = uniform_integer_cst_p (@1); + tree etype = TREE_TYPE (cst); + wide_int c = wi::to_wide (cst); } + (if (single_use (@2) + && !TYPE_OVERFLOW_TRAPS (type) + && !TYPE_OVERFLOW_SANITIZED (type) + && wi::popcount (c + 1) == 1) + (bit_and (plus @0 @1) + { build_uniform_cst + (type, wide_int_to_tree (etype, wi::bit_not (c))); })))) /* (x | y) - y -> (x & ~y) */ (simplify (minus (bit_ior:cs @0 @1) @1) diff --git a/gcc/testsuite/gcc.dg/tree-ssa/alignup-2.c b/gcc/testsuite/gcc.dg/tree-ssa/alignup-2.c new file mode 100644 index 00000000000..eb9212e728c --- /dev/null +++ b/gcc/testsuite/gcc.dg/tree-ssa/alignup-2.c @@ -0,0 +1,28 @@ +/* { dg-do compile } */ +/* { dg-options "-O2 -fdump-tree-optimized" } */ + +/* Rounding up by adding the padding is the same as rounding up with a + mask. */ + +unsigned int f1 (unsigned int x) { return x + ((-x) & 15u); } +unsigned int f2 (unsigned int x) { return ((-x) & 4095u) + x; } +unsigned long f3 (unsigned long x) { return x + ((-x) & 63ul); } + +/* The identity needs no wrapping type, a signed operand works too. */ +int f5 (int x) { return x + ((-x) & 15); } + +unsigned int f6 (unsigned int x, unsigned int *p) +{ + unsigned int pad = (-x) & 15u; + *p = pad; + return x + pad; +} + +/* Not a power of two, leave it alone. */ +unsigned int f4 (unsigned int x) { return x + ((-x) & 14u); } + +/* { dg-final { scan-tree-dump-times " & 14;" 1 "optimized" } } */ +/* { dg-final { scan-tree-dump-times " & 4294967280" 1 "optimized" } } */ +/* { dg-final { scan-tree-dump-times " & 4294963200" 1 "optimized" } } */ +/* { dg-final { scan-tree-dump-times " & -16" 1 "optimized" } } */ +/* { dg-final { scan-tree-dump-times " & 15" 1 "optimized" } } */ diff --git a/gcc/testsuite/gcc.dg/tree-ssa/alignup-overflow-1.c b/gcc/testsuite/gcc.dg/tree-ssa/alignup-overflow-1.c new file mode 100644 index 00000000000..f4995d08cc0 --- /dev/null +++ b/gcc/testsuite/gcc.dg/tree-ssa/alignup-overflow-1.c @@ -0,0 +1,10 @@ +/* { dg-do compile } */ +/* { dg-options "-O2 -ftrapv -fdump-tree-optimized" } */ + +int +f (int x) +{ + return x + ((-x) & 15); +} + +/* { dg-final { scan-tree-dump " -x" "optimized" } } */ diff --git a/gcc/testsuite/gcc.dg/tree-ssa/alignup-overflow-2.c b/gcc/testsuite/gcc.dg/tree-ssa/alignup-overflow-2.c new file mode 100644 index 00000000000..75e29d60189 --- /dev/null +++ b/gcc/testsuite/gcc.dg/tree-ssa/alignup-overflow-2.c @@ -0,0 +1,10 @@ +/* { dg-do compile } */ +/* { dg-options "-O2 -fsanitize=signed-integer-overflow -fdump-tree-optimized" } */ + +int +f (int x) +{ + return x + ((-x) & 15); +} + +/* { dg-final { scan-tree-dump "UBSAN_CHECK_SUB" "optimized" } } */ diff --git a/gcc/testsuite/gcc.dg/tree-ssa/signbit-1.c b/gcc/testsuite/gcc.dg/tree-ssa/signbit-1.c new file mode 100644 index 00000000000..d7bcd91173b --- /dev/null +++ b/gcc/testsuite/gcc.dg/tree-ssa/signbit-1.c @@ -0,0 +1,26 @@ +/* { dg-do compile } */ +/* { dg-options "-O2 -fdump-tree-optimized" } */ + +/* X | -X has the sign bit set exactly when X is non-zero. */ + +int f1 (int x) +{ return (x | -x) >> (__SIZEOF_INT__ * __CHAR_BIT__ - 1); } +unsigned int f2 (unsigned int x) +{ return (x | -x) >> (__SIZEOF_INT__ * __CHAR_BIT__ - 1); } +long f3 (long x) { return (x | -x) >> (__SIZEOF_LONG__ * __CHAR_BIT__ - 1); } + +/* X + (X | -X) clears the lowest set bit of X. The identity holds for a + signed operand too, X - 1 overflows only where the source does. */ +unsigned int f4 (unsigned int x) { return x + (x | -x); } +int f5 (int x) { return x + (x | -x); } + +unsigned int f6 (unsigned int x, unsigned int *p) +{ + unsigned int y = x | -x; + *p = y; + return x + y; +} + +/* { dg-final { scan-tree-dump-times " \\| " 1 "optimized" } } */ +/* { dg-final { scan-tree-dump-times " != 0" 3 "optimized" } } */ +/* { dg-final { scan-tree-dump-times " & " 2 "optimized" } } */ diff --git a/gcc/testsuite/gcc.dg/tree-ssa/vector-alignup-1.c b/gcc/testsuite/gcc.dg/tree-ssa/vector-alignup-1.c new file mode 100644 index 00000000000..fec5c5c6b93 --- /dev/null +++ b/gcc/testsuite/gcc.dg/tree-ssa/vector-alignup-1.c @@ -0,0 +1,15 @@ +/* { dg-do compile } */ +/* { dg-require-effective-target vect_int } */ +/* { dg-options "-O2 -fdump-tree-optimized" } */ + +/* Rounding up by adding the padding, spelled with vectors. */ + +typedef unsigned int v4ui __attribute__((vector_size (16))); +typedef int v4si __attribute__((vector_size (16))); + +v4ui f1 (v4ui x) { return x + ((-x) & 15); } +v4si f2 (v4si x) { return x + ((-x) & 63); } + +/* { dg-final { scan-tree-dump-not "= -" "optimized" } } */ +/* { dg-final { scan-tree-dump-times " \\+ " 2 "optimized" } } */ +/* { dg-final { scan-tree-dump-times " & " 2 "optimized" } } */