[gcc(refs/users/aoliva/heads/testme)] harden-conditionals: detach values before compares

Alexandre Oliva aoliva@gcc.gnu.org
Thu Jun 8 10:42:22 GMT 2023


https://gcc.gnu.org/g:848936fda2abec8bb78a4b96d1437990421fcae5

commit 848936fda2abec8bb78a4b96d1437990421fcae5
Author: Alexandre Oliva <oliva@adacore.com>
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" } } */


More information about the Gcc-cvs mailing list