Skip to content

Commit fe8c8f1

Browse files
committed
Fold &MEM[0 + CST]->a.b.c to a constant
This canonicalizes those to a constant literal. 2020-05-12 Richard Biener <rguenther@suse.de> * gimple-fold.c (maybe_canonicalize_mem_ref_addr): Canonicalize literal constant &MEM[..] to a constant literal.
1 parent bb63ca6 commit fe8c8f1

File tree

2 files changed

+31
-0
lines changed

2 files changed

+31
-0
lines changed

gcc/ChangeLog

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
1+
2020-05-12 Richard Biener <rguenther@suse.de>
2+
3+
* gimple-fold.c (maybe_canonicalize_mem_ref_addr): Canonicalize
4+
literal constant &MEM[..] to a constant literal.
5+
16
2020-05-12 Richard Biener <rguenther@suse.de>
27

38
PR tree-optimization/95045

gcc/gimple-fold.c

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4840,6 +4840,7 @@ static bool
48404840
maybe_canonicalize_mem_ref_addr (tree *t)
48414841
{
48424842
bool res = false;
4843+
tree *orig_t = t;
48434844

48444845
if (TREE_CODE (*t) == ADDR_EXPR)
48454846
t = &TREE_OPERAND (*t, 0);
@@ -4940,6 +4941,31 @@ maybe_canonicalize_mem_ref_addr (tree *t)
49404941
}
49414942
}
49424943

4944+
else if (TREE_CODE (*orig_t) == ADDR_EXPR
4945+
&& TREE_CODE (*t) == MEM_REF
4946+
&& TREE_CODE (TREE_OPERAND (*t, 0)) == INTEGER_CST)
4947+
{
4948+
tree base;
4949+
poly_int64 coffset;
4950+
base = get_addr_base_and_unit_offset (TREE_OPERAND (*orig_t, 0),
4951+
&coffset);
4952+
if (base)
4953+
{
4954+
gcc_assert (TREE_CODE (base) == MEM_REF);
4955+
poly_int64 moffset;
4956+
if (mem_ref_offset (base).to_shwi (&moffset))
4957+
{
4958+
coffset += moffset;
4959+
if (wi::to_poly_wide (TREE_OPERAND (base, 0)).to_shwi (&moffset))
4960+
{
4961+
coffset += moffset;
4962+
*orig_t = build_int_cst (TREE_TYPE (*orig_t), coffset);
4963+
return true;
4964+
}
4965+
}
4966+
}
4967+
}
4968+
49434969
/* Canonicalize TARGET_MEM_REF in particular with respect to
49444970
the indexes becoming constant. */
49454971
else if (TREE_CODE (*t) == TARGET_MEM_REF)

0 commit comments

Comments
 (0)