From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 2140) id 9053A385700D; Thu, 8 Jun 2023 10:42:22 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 9053A385700D DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1686220942; bh=ReePq67CKfurZFom2jAYzm8DELqoBAqBeKFlT+EvxrI=; h=From:To:Subject:Date:From; b=TXFN9OkIKE7j443scBNQa2MJ+gmJyfVuPJCD4wGlQY6I8P7FX9NuiBOvmQvObuTcC JoQYO3h166pg3aqFgyPyz4NhJqxSi41rDTHoY4fGjRBwHv+cz5G4DD8eN0M230u0PN swLlo1cK7RCsc5n+xrmZCbl/gentyHpKs1EyyQp4= Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit From: Alexandre Oliva To: gcc-cvs@gcc.gnu.org Subject: [gcc(refs/users/aoliva/heads/testme)] harden-conditionals: detach values before compares X-Act-Checkin: gcc X-Git-Author: Alexandre Oliva X-Git-Refname: refs/users/aoliva/heads/testme X-Git-Oldrev: 8b327e0e273d525275e6236d1048192284779732 X-Git-Newrev: 848936fda2abec8bb78a4b96d1437990421fcae5 Message-Id: <20230608104222.9053A385700D@sourceware.org> Date: Thu, 8 Jun 2023 10:42:22 +0000 (GMT) List-Id: https://gcc.gnu.org/g:848936fda2abec8bb78a4b96d1437990421fcae5 commit 848936fda2abec8bb78a4b96d1437990421fcae5 Author: Alexandre Oliva Date: Thu Apr 27 02:43:48 2023 -0300 harden-conditionals: detach values before compares The optimization barriers inserted after compares enable GCC to derive information about the values from e.g. the taken paths, or the absence of exceptions. Move them before the original compares, so that the reversed compares test copies of the original operands, without further optimizations. for gcc/ChangeLog * gimple-harden-conditionals.cc (insert_edge_check_and_trap): Move detach value calls... (pass_harden_conditional_branches::execute): ... here. (pass_harden_compares::execute): Detach values before compares. for gcc/testsuite/ChangeLog * c-c++-common/torture/harden-cond-comp.c: New. Diff: --- gcc/testsuite/c-c++-common/torture/harden-cond-comp.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/gcc/testsuite/c-c++-common/torture/harden-cond-comp.c b/gcc/testsuite/c-c++-common/torture/harden-cond-comp.c index dcf364ee993..5aad890a1d3 100644 --- a/gcc/testsuite/c-c++-common/torture/harden-cond-comp.c +++ b/gcc/testsuite/c-c++-common/torture/harden-cond-comp.c @@ -1,11 +1,11 @@ /* { dg-do compile } */ /* { dg-options "-fharden-conditional-branches -fharden-compares -fdump-tree-hardcbr -fdump-tree-hardcmp -ffat-lto-objects" } */ -int f(int i, int j, int k, int l) { +int f(int i, int j) { if (i == 0) - return (j != 0) + l; + return j != 0; else - return (i * j != 0) * k; + return i * j != 0; } /* { dg-final { scan-tree-dump-times "Splitting edge" 2 "hardcbr" } } */