aboutsummaryrefslogtreecommitdiff
path: root/gcc/dse.c
diff options
context:
space:
mode:
authorJakub Jelinek <jakub@redhat.com>2009-08-05 14:36:34 +0200
committerJakub Jelinek <jakub@gcc.gnu.org>2009-08-05 14:36:34 +0200
commit403c752036db9af05c6d40804df668d3f3cbaf52 (patch)
tree9a626f565d7bec81f41671e6ad4e4880cbb1f523 /gcc/dse.c
parent64393e407db3350e25f53e252023f84f6e321c02 (diff)
downloadgcc-403c752036db9af05c6d40804df668d3f3cbaf52.zip
gcc-403c752036db9af05c6d40804df668d3f3cbaf52.tar.gz
gcc-403c752036db9af05c6d40804df668d3f3cbaf52.tar.bz2
re PR rtl-optimization/40924 (miscompiles with -O3 (seemingly related to attribute may_alias))
PR rtl-optimization/40924 * dse.c (canon_address): Before calling cselib_expand_value_rtx make sure canon_rtx (mem_address) isn't simpler than canon_rtx (expanded_mem_address). * g++.dg/torture/pr40924.C: New test. From-SVN: r150483
Diffstat (limited to 'gcc/dse.c')
-rw-r--r--gcc/dse.c116
1 files changed, 67 insertions, 49 deletions
diff --git a/gcc/dse.c b/gcc/dse.c
index 0fc2aa9..2338d32 100644
--- a/gcc/dse.c
+++ b/gcc/dse.c
@@ -1070,6 +1070,8 @@ canon_address (rtx mem,
{
rtx mem_address = XEXP (mem, 0);
rtx expanded_address, address;
+ int expanded;
+
/* Make sure that cselib is has initialized all of the operands of
the address before asking it to do the subst. */
@@ -1114,72 +1116,88 @@ canon_address (rtx mem,
fprintf (dump_file, "\n");
}
- /* Use cselib to replace all of the reg references with the full
- expression. This will take care of the case where we have
+ /* First see if just canon_rtx (mem_address) is const or frame,
+ if not, try cselib_expand_value_rtx and call canon_rtx on that. */
+ address = NULL_RTX;
+ for (expanded = 0; expanded < 2; expanded++)
+ {
+ if (expanded)
+ {
+ /* Use cselib to replace all of the reg references with the full
+ expression. This will take care of the case where we have
- r_x = base + offset;
- val = *r_x;
+ r_x = base + offset;
+ val = *r_x;
- by making it into
-
- val = *(base + offset);
- */
-
- expanded_address = cselib_expand_value_rtx (mem_address, scratch, 5);
+ by making it into
- /* If this fails, just go with the mem_address. */
- if (!expanded_address)
- expanded_address = mem_address;
+ val = *(base + offset); */
- /* Split the address into canonical BASE + OFFSET terms. */
- address = canon_rtx (expanded_address);
+ expanded_address = cselib_expand_value_rtx (mem_address,
+ scratch, 5);
- *offset = 0;
+ /* If this fails, just go with the address from first
+ iteration. */
+ if (!expanded_address)
+ break;
+ }
+ else
+ expanded_address = mem_address;
- if (dump_file)
- {
- fprintf (dump_file, "\n after cselib_expand address: ");
- print_inline_rtx (dump_file, expanded_address, 0);
- fprintf (dump_file, "\n");
+ /* Split the address into canonical BASE + OFFSET terms. */
+ address = canon_rtx (expanded_address);
- fprintf (dump_file, "\n after canon_rtx address: ");
- print_inline_rtx (dump_file, address, 0);
- fprintf (dump_file, "\n");
- }
+ *offset = 0;
- if (GET_CODE (address) == CONST)
- address = XEXP (address, 0);
+ if (dump_file)
+ {
+ if (expanded)
+ {
+ fprintf (dump_file, "\n after cselib_expand address: ");
+ print_inline_rtx (dump_file, expanded_address, 0);
+ fprintf (dump_file, "\n");
+ }
- if (GET_CODE (address) == PLUS && CONST_INT_P (XEXP (address, 1)))
- {
- *offset = INTVAL (XEXP (address, 1));
- address = XEXP (address, 0);
- }
+ fprintf (dump_file, "\n after canon_rtx address: ");
+ print_inline_rtx (dump_file, address, 0);
+ fprintf (dump_file, "\n");
+ }
- if (const_or_frame_p (address))
- {
- group_info_t group = get_group_info (address);
+ if (GET_CODE (address) == CONST)
+ address = XEXP (address, 0);
- if (dump_file)
- fprintf (dump_file, " gid=%d offset=%d \n", group->id, (int)*offset);
- *base = NULL;
- *group_id = group->id;
- }
- else
- {
- *base = cselib_lookup (address, Pmode, true);
- *group_id = -1;
+ if (GET_CODE (address) == PLUS
+ && CONST_INT_P (XEXP (address, 1)))
+ {
+ *offset = INTVAL (XEXP (address, 1));
+ address = XEXP (address, 0);
+ }
- if (*base == NULL)
+ if (const_or_frame_p (address))
{
+ group_info_t group = get_group_info (address);
+
if (dump_file)
- fprintf (dump_file, " no cselib val - should be a wild read.\n");
- return false;
+ fprintf (dump_file, " gid=%d offset=%d \n",
+ group->id, (int)*offset);
+ *base = NULL;
+ *group_id = group->id;
+ return true;
}
+ }
+
+ *base = cselib_lookup (address, Pmode, true);
+ *group_id = -1;
+
+ if (*base == NULL)
+ {
if (dump_file)
- fprintf (dump_file, " varying cselib base=%d offset = %d\n",
- (*base)->value, (int)*offset);
+ fprintf (dump_file, " no cselib val - should be a wild read.\n");
+ return false;
}
+ if (dump_file)
+ fprintf (dump_file, " varying cselib base=%d offset = %d\n",
+ (*base)->value, (int)*offset);
return true;
}