+2020-05-12 Richard Biener <rguenther@suse.de>
+
+ * gimple-fold.c (maybe_canonicalize_mem_ref_addr): Canonicalize
+ literal constant &MEM[..] to a constant literal.
+
2020-05-12 Richard Biener <rguenther@suse.de>
PR tree-optimization/95045
maybe_canonicalize_mem_ref_addr (tree *t)
{
bool res = false;
+ tree *orig_t = t;
if (TREE_CODE (*t) == ADDR_EXPR)
t = &TREE_OPERAND (*t, 0);
}
}
+ else if (TREE_CODE (*orig_t) == ADDR_EXPR
+ && TREE_CODE (*t) == MEM_REF
+ && TREE_CODE (TREE_OPERAND (*t, 0)) == INTEGER_CST)
+ {
+ tree base;
+ poly_int64 coffset;
+ base = get_addr_base_and_unit_offset (TREE_OPERAND (*orig_t, 0),
+ &coffset);
+ if (base)
+ {
+ gcc_assert (TREE_CODE (base) == MEM_REF);
+ poly_int64 moffset;
+ if (mem_ref_offset (base).to_shwi (&moffset))
+ {
+ coffset += moffset;
+ if (wi::to_poly_wide (TREE_OPERAND (base, 0)).to_shwi (&moffset))
+ {
+ coffset += moffset;
+ *orig_t = build_int_cst (TREE_TYPE (*orig_t), coffset);
+ return true;
+ }
+ }
+ }
+ }
+
/* Canonicalize TARGET_MEM_REF in particular with respect to
the indexes becoming constant. */
else if (TREE_CODE (*t) == TARGET_MEM_REF)