diff options
author | liuhongt <hongtao.liu@intel.com> | 2023-10-30 15:43:48 +0800 |
---|---|---|
committer | liuhongt <hongtao.liu@intel.com> | 2023-11-14 09:27:20 +0800 |
commit | fd1596f9962569afff6c9298a7c79686c6950bef (patch) | |
tree | 18107f8ed10d735b92106e8ef1aca52ce3127bb2 | |
parent | d22b87864e5d476535b75098e20f8d8fdaab4f8f (diff) | |
download | gcc-fd1596f9962569afff6c9298a7c79686c6950bef.zip gcc-fd1596f9962569afff6c9298a7c79686c6950bef.tar.gz gcc-fd1596f9962569afff6c9298a7c79686c6950bef.tar.bz2 |
Handle bitop with INTEGER_CST in analyze_and_compute_bitop_with_inv_effect.
analyze_and_compute_bitop_with_inv_effect assumes the first operand is
loop invariant which is not the case when it's INTEGER_CST.
gcc/ChangeLog:
PR tree-optimization/105735
PR tree-optimization/111972
* tree-scalar-evolution.cc
(analyze_and_compute_bitop_with_inv_effect): Handle bitop with
INTEGER_CST.
gcc/testsuite/ChangeLog:
* gcc.target/i386/pr105735-3.c: New test.
-rw-r--r-- | gcc/testsuite/gcc.target/i386/pr105735-3.c | 87 | ||||
-rw-r--r-- | gcc/tree-scalar-evolution.cc | 3 |
2 files changed, 90 insertions, 0 deletions
diff --git a/gcc/testsuite/gcc.target/i386/pr105735-3.c b/gcc/testsuite/gcc.target/i386/pr105735-3.c new file mode 100644 index 0000000..9e268a1 --- /dev/null +++ b/gcc/testsuite/gcc.target/i386/pr105735-3.c @@ -0,0 +1,87 @@ +/* { dg-do compile } */ +/* { dg-options "-O1 -fdump-tree-sccp-details" } */ +/* { dg-final { scan-tree-dump-times {final value replacement} 8 "sccp" } } */ + +unsigned int +__attribute__((noipa)) +foo (unsigned int tmp) +{ + for (int bit = 0; bit < 64; bit++) + tmp &= 11304; + return tmp; +} + +unsigned int +__attribute__((noipa)) +foo1 (unsigned int tmp) +{ + for (int bit = 63; bit >= 0; bit -=3) + tmp &= 11304; + return tmp; +} + +unsigned int +__attribute__((noipa)) +foo2 (unsigned int tmp) +{ + for (int bit = 0; bit < 64; bit++) + tmp |= 11304; + return tmp; +} + +unsigned int +__attribute__((noipa)) +foo3 (unsigned int tmp) +{ + for (int bit = 63; bit >= 0; bit -=3) + tmp |= 11304; + return tmp; +} + +unsigned int +__attribute__((noipa)) +foo4 (unsigned int tmp) +{ + for (int bit = 0; bit < 64; bit++) + tmp ^= 11304; + return tmp; +} + +unsigned int +__attribute__((noipa)) +foo5 (unsigned int tmp) +{ + for (int bit = 0; bit < 63; bit++) + tmp ^= 11304; + return tmp; +} + +unsigned int +__attribute__((noipa)) +f (unsigned int tmp, int bit) +{ + unsigned int res = tmp; + for (int i = 0; i < bit; i++) + res &= 11304; + return res; +} + +unsigned int +__attribute__((noipa)) +f1 (unsigned int tmp, int bit) +{ + unsigned int res = tmp; + for (int i = 0; i < bit; i++) + res |= 11304; + return res; +} + +unsigned int +__attribute__((noipa)) +f2 (unsigned int tmp, int bit) +{ + unsigned int res = tmp; + for (int i = 0; i < bit; i++) + res ^= 11304; + return res; +} diff --git a/gcc/tree-scalar-evolution.cc b/gcc/tree-scalar-evolution.cc index 70b17c5..f61277c 100644 --- a/gcc/tree-scalar-evolution.cc +++ b/gcc/tree-scalar-evolution.cc @@ -3689,6 +3689,9 @@ analyze_and_compute_bitop_with_inv_effect (class loop* loop, tree phidef, match_op[0] = gimple_assign_rhs1 (def); match_op[1] = gimple_assign_rhs2 (def); + if (expr_invariant_in_loop_p (loop, match_op[1])) + std::swap (match_op[0], match_op[1]); + if (TREE_CODE (match_op[1]) != SSA_NAME || !expr_invariant_in_loop_p (loop, match_op[0]) || !(header_phi = dyn_cast <gphi *> (SSA_NAME_DEF_STMT (match_op[1]))) |