diff options
author | Andrew Pinski <apinski@marvell.com> | 2021-11-23 01:08:55 +0000 |
---|---|---|
committer | Andrew Pinski <apinski@marvell.com> | 2021-11-23 09:55:47 +0000 |
commit | 911b633803dcbb298c98777e29fd260834c0d04a (patch) | |
tree | 4be00424c1588251e016475423e78b35071d53b1 /gcc/gimple-fold.c | |
parent | 5e9b973bd60185f221222022f56db7df3d92250e (diff) | |
download | gcc-911b633803dcbb298c98777e29fd260834c0d04a.zip gcc-911b633803dcbb298c98777e29fd260834c0d04a.tar.gz gcc-911b633803dcbb298c98777e29fd260834c0d04a.tar.bz2 |
Canonicalize &MEM[ssa_n, CST] to ssa_n p+ CST in fold_stmt_1
This is a new version of the patch to fix PR 102216.
Instead of doing the canonicalization inside forwprop, Richi
mentioned we should do it inside fold_stmt_1 and that is what
this patch does.
PR tree-optimization/102216
gcc/ChangeLog:
* gimple-fold.c (fold_stmt_1): Add canonicalization
of "&MEM[ssa_n, CST]" to "ssa_n p+ CST", note this
can only be done if !in_place.
gcc/testsuite/ChangeLog:
* g++.dg/tree-ssa/pr102216-1.C: New test.
* g++.dg/tree-ssa/pr102216-2.C: New test.
Diffstat (limited to 'gcc/gimple-fold.c')
-rw-r--r-- | gcc/gimple-fold.c | 22 |
1 files changed, 22 insertions, 0 deletions
diff --git a/gcc/gimple-fold.c b/gcc/gimple-fold.c index ad9703e..73f090b 100644 --- a/gcc/gimple-fold.c +++ b/gcc/gimple-fold.c @@ -6061,6 +6061,28 @@ fold_stmt_1 (gimple_stmt_iterator *gsi, bool inplace, tree (*valueize) (tree)) if (REFERENCE_CLASS_P (*lhs) && maybe_canonicalize_mem_ref_addr (lhs)) changed = true; + /* Canonicalize &MEM[ssa_n, CST] to ssa_n p+ CST. + This cannot be done in maybe_canonicalize_mem_ref_addr + as the gimple now has two operands rather than one. + The same reason why this can't be done in + maybe_canonicalize_mem_ref_addr is the same reason why + this can't be done inplace. */ + if (!inplace && TREE_CODE (*rhs) == ADDR_EXPR) + { + tree inner = TREE_OPERAND (*rhs, 0); + if (TREE_CODE (inner) == MEM_REF + && TREE_CODE (TREE_OPERAND (inner, 0)) == SSA_NAME + && TREE_CODE (TREE_OPERAND (inner, 1)) == INTEGER_CST) + { + tree ptr = TREE_OPERAND (inner, 0); + tree addon = TREE_OPERAND (inner, 1); + addon = fold_convert (sizetype, addon); + gimple_assign_set_rhs_with_ops (gsi, POINTER_PLUS_EXPR, + ptr, addon); + changed = true; + stmt = gsi_stmt (*gsi); + } + } } else { |