From patchwork Wed Jan 10 14:19:32 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tamar Christina X-Patchwork-Id: 1884999 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=armh.onmicrosoft.com header.i=@armh.onmicrosoft.com header.a=rsa-sha256 header.s=selector2-armh-onmicrosoft-com header.b=NWkoLYMJ; dkim=pass (1024-bit key) header.d=armh.onmicrosoft.com header.i=@armh.onmicrosoft.com header.a=rsa-sha256 header.s=selector2-armh-onmicrosoft-com header.b=NWkoLYMJ; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=gcc.gnu.org (client-ip=8.43.85.97; helo=server2.sourceware.org; envelope-from=gcc-patches-bounces+incoming=patchwork.ozlabs.org@gcc.gnu.org; receiver=patchwork.ozlabs.org) Received: from server2.sourceware.org (server2.sourceware.org [8.43.85.97]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (secp384r1) server-digest SHA384) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4T991b003Pz1xqk for ; Thu, 11 Jan 2024 01:20:18 +1100 (AEDT) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id A55193857B88 for ; Wed, 10 Jan 2024 14:20:16 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from EUR04-HE1-obe.outbound.protection.outlook.com (mail-he1eur04on2057.outbound.protection.outlook.com [40.107.7.57]) by sourceware.org (Postfix) with ESMTPS id D57053857BAC for ; Wed, 10 Jan 2024 14:19:47 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org D57053857BAC Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=arm.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=arm.com ARC-Filter: OpenARC Filter v1.0.0 sourceware.org D57053857BAC Authentication-Results: server2.sourceware.org; arc=pass smtp.remote-ip=40.107.7.57 ARC-Seal: i=3; a=rsa-sha256; d=sourceware.org; s=key; t=1704896390; cv=pass; b=RaRXfG3OcJoz4nboTL0q+BDWManR5wDeaFqjq7F+A0YdXPMMoBn9sUZVVtryoIisgKdwQmk8PUz+LzayMZGXmGDDoNMXb0c/R8OjHdGlp5piIJcL8ydtwFJHLvQUFz6mxBow07y6HMSUkBsEpqAkLxw3PWf6FhrRJ8huNZrTJQM= ARC-Message-Signature: i=3; a=rsa-sha256; d=sourceware.org; s=key; t=1704896390; c=relaxed/simple; bh=k+fgWD2fXomgn/tb/Xi5rBMVY9vKirrHD+XssBcSKsk=; h=DKIM-Signature:DKIM-Signature:Date:From:To:Subject:Message-ID: MIME-Version; b=coFZhauggLbBUV03qXnv2scAlc8C+8R/XdYjHMPS2t/MMx7Fj4jalrqi0MIzPsD8Gh5A1ydtSn33UEuMj4oFWnFncgQrkKGrYZXZm0+6hDMPvdOIsh5VEGTpHxdTlDL0swLxNSJ+2Em/mTJQw/NfiaAxG4lfGWFjN7gbR7AZirM= ARC-Authentication-Results: i=3; server2.sourceware.org ARC-Seal: i=2; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=pass; b=WN+XV75MiIhaLU7MgZZ/YNK9lP8xM/QYbLCY2zyh+kwhRkEDnKxQiLo2cgjaUNtGl1gF8jqoK0BRctTtbsbhkFZ0cMF1nCr6q7fPTf2nxKZdqqRKeRTaX6X6Xq/iGInwqgAyvzjAaHXSX4Ur5mp9UnldV3onAo1eldtn1ReJ4Xp8VayFYKbePCI8Ge4IcPLN5BBD2grJ0MYnJPVUthV2Ysm+tjxOE/MTYxpKi9lNPNRyYMtdi0x6NegppsAdVh+c17XIK/YEz8dnJxn7lE/HqlmgIzR45XXC1Rzq8aI6RflIwFbQ84V+IHe9om3s6FdWk182B4xqOurwC97PewdHcw== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; 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=vqVDj9pbOaJyyej9ztsZUgsNndY39HbiEPsWMBr27JY=; b=DoOIZLZ1m7moJrNh+yio3hEQ4m+4FNEHpj9GSCGIjIU62HLOFlDxEeywyosjgM3bKMK7vT6B+xOj7XfSxi3nF/VLQdEldyJrn+PedUbmJXae8nkUJ6/aca7IXbEm5nPKKCHdlm7k/+HyctUnP5qdzRDI8I7VuVZt7BbVcvSqy5xLuz7eV8vImkGfpRS9jdv84/dtBkL5O579l3F1NXPQKDEGVSJjR9ZS2Va/EWHTun9MpedgPzbuMC4wST1+d3PAH09mLYdIQIe48Yg3JtmuOQMLT3b67Fa2ndXms5hvDOWUSBNybgf497M1MgSCzaF/UCIn3BDDsDf0gY0IfVnVwg== ARC-Authentication-Results: i=2; mx.microsoft.com 1; spf=pass (sender ip is 63.35.35.123) smtp.rcpttodomain=gcc.gnu.org smtp.mailfrom=arm.com; dmarc=pass (p=none sp=none pct=100) action=none header.from=arm.com; dkim=pass (signature was verified) header.d=armh.onmicrosoft.com; arc=pass (0 oda=1 ltdi=1 spf=[1,1,smtp.mailfrom=arm.com] dkim=[1,1,header.d=arm.com] dmarc=[1,1,header.from=arm.com]) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=armh.onmicrosoft.com; s=selector2-armh-onmicrosoft-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=vqVDj9pbOaJyyej9ztsZUgsNndY39HbiEPsWMBr27JY=; b=NWkoLYMJtKDHwJrBWOwq2EY9jKdma/EnJepB94BrvMQxUjNAsTTsk3sHytNEoIiOTuxHBBzleibeE+U5OdCWF8qCFr1QgLZTuC+rxcyhkFy5itUmtzcDrtNzO+zXS92eOX9QsDPtLJFaVls3y6XFe4vqyBMSP7eagH7r1FWaKAI= Received: from AS9PR04CA0061.eurprd04.prod.outlook.com (2603:10a6:20b:48b::15) by VI0PR08MB10581.eurprd08.prod.outlook.com (2603:10a6:800:20e::10) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7181.17; Wed, 10 Jan 2024 14:19:44 +0000 Received: from AM2PEPF0001C70D.eurprd05.prod.outlook.com (2603:10a6:20b:48b:cafe::81) by AS9PR04CA0061.outlook.office365.com (2603:10a6:20b:48b::15) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7181.17 via Frontend Transport; Wed, 10 Jan 2024 14:19:44 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 63.35.35.123) smtp.mailfrom=arm.com; dkim=pass (signature was verified) header.d=armh.onmicrosoft.com;dmarc=pass action=none header.from=arm.com; Received-SPF: Pass (protection.outlook.com: domain of arm.com designates 63.35.35.123 as permitted sender) receiver=protection.outlook.com; client-ip=63.35.35.123; helo=64aa7808-outbound-1.mta.getcheckrecipient.com; pr=C Received: from 64aa7808-outbound-1.mta.getcheckrecipient.com (63.35.35.123) by AM2PEPF0001C70D.mail.protection.outlook.com (10.167.16.201) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7181.14 via Frontend Transport; Wed, 10 Jan 2024 14:19:43 +0000 Received: ("Tessian outbound c87008563c51:v228"); Wed, 10 Jan 2024 14:19:43 +0000 X-CheckRecipientChecked: true X-CR-MTA-CID: 8c015d07664d3d95 X-CR-MTA-TID: 64aa7808 Received: from 8e13bb479653.1 by 64aa7808-outbound-1.mta.getcheckrecipient.com id F004BB73-B633-41A7-BB0D-06AAF2506F91.1; Wed, 10 Jan 2024 14:19:36 +0000 Received: from EUR05-AM6-obe.outbound.protection.outlook.com by 64aa7808-outbound-1.mta.getcheckrecipient.com with ESMTPS id 8e13bb479653.1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384); Wed, 10 Jan 2024 14:19:36 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=djcSxISxJqveVA7Mc3G+b9+SYGLU/LfwmCbS34NjaBY8Cymf2Yd5NNZApQfSd6WG+srloJUL/jJ6duL3hnJfpFMSQlGkFdLWq5PDCVLqrlMXtsQtQBCQhifE2rxLG1XODGWhe3ImnIBi/pUugx/Y7bWFjb++25cbj/qF/Aj8J+BTbzrjtZqr5yH2vtBEzDth0Qq3wuMrjKUdZ7fCKlh7mQDySXl0L0ZTaT5mSQosbkzuxL7yZnSz/FB6qVmjkcbFSgGpgTOdNWM6XGKi/FNrZKVkd1umMoLj29bpw9AW3tRNL07AS4oEhDoQlsssJNIxzUMxZpwYNAlzov5NjUMNpA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; 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=vqVDj9pbOaJyyej9ztsZUgsNndY39HbiEPsWMBr27JY=; b=YdEIF1+UbFQXWVGEwRsOCfphXWy9H1LrCPakOl5XBigE0eD3N0enIQBLigjURP/n4ZHehrK+Je2l7yLB1qNMAqf1VbNKwVhJQHTDT8nKB15Pa/2goZuPRc6xNm1I7PEpYnDIzfQ4fxppUoljiTQQ9DTt5auwWxNwArzI7nRrXMcGVxRkRr9HFfMShAEDTQUWCKoGm6got6sEKqKq29NbcvDh1MAVLTDRJLtR9hR6aG4IsgX9IybMVSnGtGEguc1Ho8ePIMXAHw+7efc/Q1W3NnfLeIkvwvSNZm8H8lvr+0An41TlGxm0fUEsWa0NgHzJnDoM3MEZ2GqODQL/1YLZ0A== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=arm.com; dmarc=pass action=none header.from=arm.com; dkim=pass header.d=arm.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=armh.onmicrosoft.com; s=selector2-armh-onmicrosoft-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=vqVDj9pbOaJyyej9ztsZUgsNndY39HbiEPsWMBr27JY=; b=NWkoLYMJtKDHwJrBWOwq2EY9jKdma/EnJepB94BrvMQxUjNAsTTsk3sHytNEoIiOTuxHBBzleibeE+U5OdCWF8qCFr1QgLZTuC+rxcyhkFy5itUmtzcDrtNzO+zXS92eOX9QsDPtLJFaVls3y6XFe4vqyBMSP7eagH7r1FWaKAI= Authentication-Results-Original: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=arm.com; Received: from VI1PR08MB5325.eurprd08.prod.outlook.com (2603:10a6:803:13e::17) by DU0PR08MB7566.eurprd08.prod.outlook.com (2603:10a6:10:31e::16) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7159.23; Wed, 10 Jan 2024 14:19:34 +0000 Received: from VI1PR08MB5325.eurprd08.prod.outlook.com ([fe80::810c:8495:3f0a:ef8]) by VI1PR08MB5325.eurprd08.prod.outlook.com ([fe80::810c:8495:3f0a:ef8%6]) with mapi id 15.20.7181.015; Wed, 10 Jan 2024 14:19:34 +0000 Date: Wed, 10 Jan 2024 14:19:32 +0000 From: Tamar Christina To: gcc-patches@gcc.gnu.org Cc: nd@arm.com, rguenther@suse.de, jlaw@ventanamicro.com Subject: [PATCH]middle-end: correctly identify the edge taken when condition is true. [PR113287] Message-ID: Content-Disposition: inline X-ClientProxiedBy: LO3P123CA0031.GBRP123.PROD.OUTLOOK.COM (2603:10a6:600:388::10) To VI1PR08MB5325.eurprd08.prod.outlook.com (2603:10a6:803:13e::17) MIME-Version: 1.0 X-MS-TrafficTypeDiagnostic: VI1PR08MB5325:EE_|DU0PR08MB7566:EE_|AM2PEPF0001C70D:EE_|VI0PR08MB10581:EE_ X-MS-Office365-Filtering-Correlation-Id: 558d9f8c-84ad-400e-bd33-08dc11e7312e x-checkrecipientrouted: true NoDisclaimer: true X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam-Untrusted: BCL:0; X-Microsoft-Antispam-Message-Info-Original: uB+M+Pn3WfPpDQFnqrPneDOH4cDThW3xQTuI+5DDlycH6QBoTBQYHQsO1LoeM3jLXFnDT/YyAEILOZlN1jWE6rb5tdFydrPF5RIl8/0v7PaMaypXennJxFq+l1m3wJXAw1qLFmy1RGLPqu7t8sGnZna/4n9LvIPrpMFzZ9U5zmEWRjuip2fLRGGXyEyFB2nmoTMw6VTr+xpqGnrQTMAYFz71cmzY84zRPccmaQp6SpUIspBntP4S7/8yke94rcQzpl2InuhGQ64drZzUFjNbust5w6AlIEJbFyfhYAVGNqs2VE+tBGNoen+965khyfAJl9ESCGjx9F923j4NkzaRH6RhhiJJICX2353qEIftQE1I6E1zJktnJKcUTjmO8nbTrBadxCDybOHohdPirmKwCchW3EsF2+g/0uoJjKwR38AbVuomI0YCCtAEbMjgE/lnOwj3TWtHCAD0IekDuQMIO7PTj4nUkWBWusoOMvanYDKXgat04/a/gtNb6Ab+TQv6HxQgsjab31c35+CddHmYJt4VQBA+QN5fW9dVjV1rmXh28qamHARoTkXcHHfzYsBYi18X3DWUHeVi8mTCp2XYBXl7pE9OV2nCWOoS3dNtK8EKV1AJKB6A4GJsc8AMbrtl X-Forefront-Antispam-Report-Untrusted: CIP:255.255.255.255; CTRY:; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:VI1PR08MB5325.eurprd08.prod.outlook.com; PTR:; CAT:NONE; SFS:(13230031)(39860400002)(376002)(396003)(366004)(346002)(136003)(230922051799003)(64100799003)(186009)(451199024)(1800799012)(84970400001)(316002)(66946007)(41300700001)(86362001)(36756003)(4743002)(2616005)(6512007)(26005)(6506007)(38100700002)(2906002)(33964004)(6916009)(6486002)(66476007)(44144004)(66556008)(5660300002)(478600001)(235185007)(44832011)(8936002)(8676002)(4326008)(4216001)(2700100001); DIR:OUT; SFP:1101; X-MS-Exchange-Transport-CrossTenantHeadersStamped: DU0PR08MB7566 Original-Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=arm.com; X-EOPAttributedMessage: 0 X-MS-Exchange-Transport-CrossTenantHeadersStripped: AM2PEPF0001C70D.eurprd05.prod.outlook.com X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id-Prvs: c669a6f6-9f7c-4eca-3a90-08dc11e72b68 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: Dc4WcONCJElf9fHp7IFviBwPOTyoj7Xbmlb3/o9iRUDN7pEI/HyJjBYcZUWQ1vYFFaOX4HhaheYpe1mZFTn1KCqaSDG4xrQPl3z1Ui2zPGpaeOcK7rmWN2LGI/56NpUjQt5v+I0WhM5f+qhJNbF2QoEVwhdZ4PrDDxwJDsBuEcfIu8G1+gWw21RumDLneCVPlEaJWjLoGXvnAcHIWXQ8TaMWtnS4qWXnqtfbRmzpLL/nEIqiN3l5WJTggz2fB0IQ8MMHOs653pDuOjTA7t8e2Cv0exhN1lBdbfkRbdIKIJnNalMTf30o22rJlvTC+oMRwJ2UmI5/7ZIvMsxMZSpKkEHe2SlT3difhiEb02xY5t2OG73gfxiw1OKWU9TWHZLwt8OKG2chSAC1Tb2gtosAznDBG+tavyP7bzoByIG8HbM6QZd5BxrPwXkSd8YDt9aZVT/+O1dZwzLNoGqSmQm2KrpQXZHvW0Egy9lJPjUExuyhVj981F3pLmA1lo3LLTYLnLppC7tE/K9T9OI8STMnpCwwjHGx7E+qc80gMVMIs2IfRB0sjZ3cQ6i3dcoyYDtzCBCm7sX3q0sCWs5cpTNCABsZ6nhlw3mNfk8wA+w0QUn5nvouRvnQx6XDM3nqiFWKLEq2SFytazBeienUhakwk7HPZvSWXgd80GvTWaU9JMJLHXzxlfLf7DFcOQr+99fZHhLchglX4V3qWhmNyNWz6rsgirZdnWwO35Zn+g9OlRx5FA5wf0R8KOMnDqGmlt08yjAIlGETok9YeMSTJCUpZA== X-Forefront-Antispam-Report: CIP:63.35.35.123; CTRY:IE; LANG:en; SCL:1; SRV:; IPV:CAL; SFV:NSPM; H:64aa7808-outbound-1.mta.getcheckrecipient.com; PTR:ec2-63-35-35-123.eu-west-1.compute.amazonaws.com; CAT:NONE; SFS:(13230031)(4636009)(396003)(376002)(39860400002)(346002)(136003)(230922051799003)(1800799012)(451199024)(82310400011)(186009)(64100799003)(40470700004)(46966006)(36840700001)(41300700001)(47076005)(6506007)(33964004)(44144004)(336012)(4743002)(40460700003)(40480700001)(84970400001)(2906002)(70586007)(70206006)(6916009)(316002)(6486002)(36860700001)(6512007)(478600001)(26005)(107886003)(2616005)(86362001)(356005)(82740400003)(81166007)(8676002)(235185007)(36756003)(8936002)(4326008)(44832011)(5660300002)(4216001)(2700100001); DIR:OUT; SFP:1101; X-OriginatorOrg: arm.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 10 Jan 2024 14:19:43.9407 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 558d9f8c-84ad-400e-bd33-08dc11e7312e X-MS-Exchange-CrossTenant-Id: f34e5979-57d9-4aaa-ad4d-b122a662184d X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=f34e5979-57d9-4aaa-ad4d-b122a662184d; Ip=[63.35.35.123]; Helo=[64aa7808-outbound-1.mta.getcheckrecipient.com] X-MS-Exchange-CrossTenant-AuthSource: AM2PEPF0001C70D.eurprd05.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: VI0PR08MB10581 X-Spam-Status: No, score=-11.9 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, FORGED_SPF_HELO, GIT_PATCH_0, KAM_DMARC_NONE, KAM_LOTSOFHASH, RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H2, SPF_HELO_PASS, SPF_NONE, TXREP, T_SCC_BODY_TEXT_LINE, UNPARSEABLE_RELAY autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.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+incoming=patchwork.ozlabs.org@gcc.gnu.org Hi All, The vectorizer needs to know during early break vectorization whether the edge that will be taken if the condition is true stays or leaves the loop. This is because the code assumes that if you take the true branch you exit the loop. If you don't exit the loop it has to generate a different condition. Basically it uses this information to decide whether it's generating a "any element" or an "all element" check. Bootstrapped Regtested on aarch64-none-linux-gnu, x86_64-pc-linux-gnu and no issues with --enable-lto --with-build-config=bootstrap-O3 --enable-checking=release,yes,rtl,extra. Ok for master? Thanks, Tamar gcc/ChangeLog: PR tree-optimization/113287 * tree-vect-stmts.cc (vectorizable_early_exit): Check the flags on edge instead of using BRANCH_EDGE to determine true edge. gcc/testsuite/ChangeLog: PR tree-optimization/113287 * gcc.dg/vect/vect-early-break_100-pr113287.c: New test. * gcc.dg/vect/vect-early-break_99-pr113287.c: New test. --- inline copy of patch -- diff --git a/gcc/testsuite/gcc.dg/vect/vect-early-break_100-pr113287.c b/gcc/testsuite/gcc.dg/vect/vect-early-break_100-pr113287.c new file mode 100644 index 0000000000000000000000000000000000000000..f908e5bc60779c148dc95bda3e200383d12b9e1e --- diff --git a/gcc/testsuite/gcc.dg/vect/vect-early-break_100-pr113287.c b/gcc/testsuite/gcc.dg/vect/vect-early-break_100-pr113287.c new file mode 100644 index 0000000000000000000000000000000000000000..f908e5bc60779c148dc95bda3e200383d12b9e1e --- /dev/null +++ b/gcc/testsuite/gcc.dg/vect/vect-early-break_100-pr113287.c @@ -0,0 +1,35 @@ +/* { dg-add-options vect_early_break } */ +/* { dg-require-effective-target vect_early_break } */ +/* { dg-require-effective-target vect_int } */ +/* { dg-require-effective-target bitint } */ + +__attribute__((noipa)) void +bar (unsigned long *p) +{ + __builtin_memset (p, 0, 142 * sizeof (unsigned long)); + p[17] = 0x50000000000UL; +} + +__attribute__((noipa)) int +foo (void) +{ + unsigned long r[142]; + bar (r); + unsigned long v = ((long) r[0] >> 31); + if (v + 1 > 1) + return 1; + for (unsigned long i = 1; i <= 140; ++i) + if (r[i] != v) + return 1; + unsigned long w = r[141]; + if ((unsigned long) (((long) (w << 60)) >> 60) != v) + return 1; + return 0; +} + +int +main () +{ + if (foo () != 1) + __builtin_abort (); +} diff --git a/gcc/testsuite/gcc.dg/vect/vect-early-break_99-pr113287.c b/gcc/testsuite/gcc.dg/vect/vect-early-break_99-pr113287.c new file mode 100644 index 0000000000000000000000000000000000000000..b92a8a268d803ab1656b4716b1a319ed4edc87a3 --- /dev/null +++ b/gcc/testsuite/gcc.dg/vect/vect-early-break_99-pr113287.c @@ -0,0 +1,32 @@ +/* { dg-add-options vect_early_break } */ +/* { dg-require-effective-target vect_early_break } */ +/* { dg-require-effective-target vect_int } */ +/* { dg-require-effective-target bitint } */ + +_BitInt(998) b; +char c; +char d; +char e; +char f; +char g; +char h; +char i; +char j; + +void +foo(char y, _BitInt(9020) a, char *r) +{ + char x = __builtin_mul_overflow_p(a << sizeof(a), y, 0); + x += c + d + e + f + g + h + i + j + b; + *r = x; +} + +int +main(void) +{ + char x; + foo(5, 5, &x); + if (x != 1) + __builtin_abort(); + return 0; +} diff --git a/gcc/tree-vect-stmts.cc b/gcc/tree-vect-stmts.cc index 1333d8934783acdb5277e3a03c2b4021fec4777b..da004b0e9e2696cd2ce358d3b221851c7b60b448 100644 --- a/gcc/tree-vect-stmts.cc +++ b/gcc/tree-vect-stmts.cc @@ -12870,13 +12870,18 @@ vectorizable_early_exit (vec_info *vinfo, stmt_vec_info stmt_info, rewrite conditions to always be a comparison against 0. To do this it sometimes flips the edges. This is fine for scalar, but for vector we then have to flip the test, as we're still assuming that if you take the - branch edge that we found the exit condition. */ + branch edge that we found the exit condition. i.e. we need to know whether + we are generating a `forall` or an `exist` condition. */ auto new_code = NE_EXPR; auto reduc_optab = ior_optab; auto reduc_op = BIT_IOR_EXPR; tree cst = build_zero_cst (vectype); + edge exit_true_edge = EDGE_SUCC (gimple_bb (cond_stmt), 0); + if (exit_true_edge->flags & EDGE_FALSE_VALUE) + exit_true_edge = EDGE_SUCC (gimple_bb (cond_stmt), 1); + gcc_assert (exit_true_edge->flags & EDGE_TRUE_VALUE); if (flow_bb_inside_loop_p (LOOP_VINFO_LOOP (loop_vinfo), - BRANCH_EDGE (gimple_bb (cond_stmt))->dest)) + exit_true_edge->dest)) { new_code = EQ_EXPR; reduc_optab = and_optab; --- /dev/null +++ b/gcc/testsuite/gcc.dg/vect/vect-early-break_100-pr113287.c @@ -0,0 +1,35 @@ +/* { dg-add-options vect_early_break } */ +/* { dg-require-effective-target vect_early_break } */ +/* { dg-require-effective-target vect_int } */ +/* { dg-require-effective-target bitint } */ + +__attribute__((noipa)) void +bar (unsigned long *p) +{ + __builtin_memset (p, 0, 142 * sizeof (unsigned long)); + p[17] = 0x50000000000UL; +} + +__attribute__((noipa)) int +foo (void) +{ + unsigned long r[142]; + bar (r); + unsigned long v = ((long) r[0] >> 31); + if (v + 1 > 1) + return 1; + for (unsigned long i = 1; i <= 140; ++i) + if (r[i] != v) + return 1; + unsigned long w = r[141]; + if ((unsigned long) (((long) (w << 60)) >> 60) != v) + return 1; + return 0; +} + +int +main () +{ + if (foo () != 1) + __builtin_abort (); +} diff --git a/gcc/testsuite/gcc.dg/vect/vect-early-break_99-pr113287.c b/gcc/testsuite/gcc.dg/vect/vect-early-break_99-pr113287.c new file mode 100644 index 0000000000000000000000000000000000000000..b92a8a268d803ab1656b4716b1a319ed4edc87a3 --- /dev/null +++ b/gcc/testsuite/gcc.dg/vect/vect-early-break_99-pr113287.c @@ -0,0 +1,32 @@ +/* { dg-add-options vect_early_break } */ +/* { dg-require-effective-target vect_early_break } */ +/* { dg-require-effective-target vect_int } */ +/* { dg-require-effective-target bitint } */ + +_BitInt(998) b; +char c; +char d; +char e; +char f; +char g; +char h; +char i; +char j; + +void +foo(char y, _BitInt(9020) a, char *r) +{ + char x = __builtin_mul_overflow_p(a << sizeof(a), y, 0); + x += c + d + e + f + g + h + i + j + b; + *r = x; +} + +int +main(void) +{ + char x; + foo(5, 5, &x); + if (x != 1) + __builtin_abort(); + return 0; +} diff --git a/gcc/tree-vect-stmts.cc b/gcc/tree-vect-stmts.cc index 1333d8934783acdb5277e3a03c2b4021fec4777b..da004b0e9e2696cd2ce358d3b221851c7b60b448 100644 --- a/gcc/tree-vect-stmts.cc +++ b/gcc/tree-vect-stmts.cc @@ -12870,13 +12870,18 @@ vectorizable_early_exit (vec_info *vinfo, stmt_vec_info stmt_info, rewrite conditions to always be a comparison against 0. To do this it sometimes flips the edges. This is fine for scalar, but for vector we then have to flip the test, as we're still assuming that if you take the - branch edge that we found the exit condition. */ + branch edge that we found the exit condition. i.e. we need to know whether + we are generating a `forall` or an `exist` condition. */ auto new_code = NE_EXPR; auto reduc_optab = ior_optab; auto reduc_op = BIT_IOR_EXPR; tree cst = build_zero_cst (vectype); + edge exit_true_edge = EDGE_SUCC (gimple_bb (cond_stmt), 0); + if (exit_true_edge->flags & EDGE_FALSE_VALUE) + exit_true_edge = EDGE_SUCC (gimple_bb (cond_stmt), 1); + gcc_assert (exit_true_edge->flags & EDGE_TRUE_VALUE); if (flow_bb_inside_loop_p (LOOP_VINFO_LOOP (loop_vinfo), - BRANCH_EDGE (gimple_bb (cond_stmt))->dest)) + exit_true_edge->dest)) { new_code = EQ_EXPR; reduc_optab = and_optab;