diff options
author | Richard Biener <rguenther@suse.de> | 2023-07-04 10:29:26 +0200 |
---|---|---|
committer | Richard Biener <rguenther@suse.de> | 2023-07-04 11:11:45 +0200 |
commit | b083203f053f1666e9cc1ded2abdf4e1688d1ec0 (patch) | |
tree | d7ef796b7d23e69b71ec198f8c48c6c52769af83 /gcc | |
parent | 729aa4fa48d627c4344764676edad3b65d40a003 (diff) | |
download | gcc-b083203f053f1666e9cc1ded2abdf4e1688d1ec0.zip gcc-b083203f053f1666e9cc1ded2abdf4e1688d1ec0.tar.gz gcc-b083203f053f1666e9cc1ded2abdf4e1688d1ec0.tar.bz2 |
tree-optimization/110228 - avoid undefs in ifcombine more thoroughly
The following replaces the simplistic gimple_uses_undefined_value_p
with the conservative mark_ssa_maybe_undefs approach as already
used by LIM and IVOPTs. This is to avoid exposing an unconditional
uninitialized read on a path from entry by if-combine.
PR tree-optimization/110228
* tree-ssa-ifcombine.cc (pass_tree_ifcombine::execute):
Mark SSA may-undefs.
(bb_no_side_effects_p): Check stmt uses for undefs.
* gcc.dg/torture/pr110228.c: New testcase.
* gcc.dg/uninit-pr101912.c: Un-XFAIL.
Diffstat (limited to 'gcc')
-rw-r--r-- | gcc/testsuite/gcc.dg/torture/pr110228.c | 34 | ||||
-rw-r--r-- | gcc/testsuite/gcc.dg/uninit-pr101912.c | 2 | ||||
-rw-r--r-- | gcc/tree-ssa-ifcombine.cc | 8 |
3 files changed, 42 insertions, 2 deletions
diff --git a/gcc/testsuite/gcc.dg/torture/pr110228.c b/gcc/testsuite/gcc.dg/torture/pr110228.c new file mode 100644 index 0000000..add9f17 --- /dev/null +++ b/gcc/testsuite/gcc.dg/torture/pr110228.c @@ -0,0 +1,34 @@ +/* { dg-do run { target x86_64-*-* i?86-*-* } } */ +/* { dg-require-effective-target lp64 } */ + +unsigned a[4] = {1,1,1,1}; +unsigned tt1 = 0; + +__attribute__((noipa)) +static void bug(unsigned * p, unsigned *t, int n, int t2) +{ + for(int i = 0; i < n; i++) + { + _Bool LookupFlags ; + unsigned v = t[i]; + unsigned tt = tt1; + if (v == 0) + LookupFlags = 0; + else if (v == 1) + LookupFlags = 1; + if (LookupFlags) { + tt|=3u; + LookupFlags = 0; + } + asm("movq $-1, %q1":"+a"(LookupFlags)); + *p = tt; + } +} + +int main() +{ + unsigned r = 42; + bug(&r,a, sizeof(a)/sizeof(a[0]), 1); + __builtin_printf("%u\n", r); + if (r != 3) __builtin_abort(); +} diff --git a/gcc/testsuite/gcc.dg/uninit-pr101912.c b/gcc/testsuite/gcc.dg/uninit-pr101912.c index 62cd2a0..cb7d751 100644 --- a/gcc/testsuite/gcc.dg/uninit-pr101912.c +++ b/gcc/testsuite/gcc.dg/uninit-pr101912.c @@ -11,7 +11,7 @@ tzloadbody (void) for (int i = 0; i < n; i++) { int corr = getint (); - if (corr < 1 || (corr == 1 && !(leapcnt == 0 || (prevcorr < corr ? corr == prevcorr + 1 : (corr == prevcorr || corr == prevcorr - 1))))) /* { dg-bogus "uninitialized" "pr101912" { xfail *-*-* } } */ + if (corr < 1 || (corr == 1 && !(leapcnt == 0 || (prevcorr < corr ? corr == prevcorr + 1 : (corr == prevcorr || corr == prevcorr - 1))))) /* { dg-bogus "uninitialized" "pr101912" } */ return -1; prevcorr = corr; diff --git a/gcc/tree-ssa-ifcombine.cc b/gcc/tree-ssa-ifcombine.cc index 21a77dd..58e19c1 100644 --- a/gcc/tree-ssa-ifcombine.cc +++ b/gcc/tree-ssa-ifcombine.cc @@ -128,7 +128,6 @@ bb_no_side_effects_p (basic_block bb) gassign *ass; enum tree_code rhs_code; if (gimple_has_side_effects (stmt) - || gimple_uses_undefined_value_p (stmt) || gimple_could_trap_p (stmt) || gimple_vuse (stmt) /* We need to rewrite stmts with undefined overflow to use @@ -153,6 +152,12 @@ bb_no_side_effects_p (basic_block bb) should handle this. */ || is_gimple_call (stmt)) return false; + + ssa_op_iter it; + tree use; + FOR_EACH_SSA_TREE_OPERAND (use, stmt, it, SSA_OP_USE) + if (ssa_name_maybe_undef_p (use)) + return false; } return true; @@ -836,6 +841,7 @@ pass_tree_ifcombine::execute (function *fun) bbs = single_pred_before_succ_order (); calculate_dominance_info (CDI_DOMINATORS); + mark_ssa_maybe_undefs (); /* Search every basic block for COND_EXPR we may be able to optimize. |