Skip to content

Commit 4fbe8f4

Browse files
committed
cse: Check volatile memory in cselib_redundant_set_p
For h8300-elf, gcc.dg/pr114768.c fails when compiled with -O2 -msx since cselib_redundant_set_p returns true when called with (gdb) call debug (set) (set (mem:HI (reg/f:SI 0 r0 [orig:21 p ] [21]) [1 *p_3(D)+0 S2 A16]) (mem/v:HI (reg/f:SI 0 r0 [orig:21 p ] [21]) [1 MEM[(volatile int *)p_3(D)]+0 S2 A16])) (gdb) from reload_cse_regs. Update cselib_redundant_set_p to return false for volatile memory source or destination. gcc/ PR target/122343 * cselib.cc (cselib_redundant_set_p): Return false for volatile memory source or destination. gcc/testsuite/ PR target/122343 * gcc.dg/pr122343-1.c: New test. Signed-off-by: H.J. Lu <[email protected]>
1 parent 278eb0a commit 4fbe8f4

File tree

2 files changed

+15
-2
lines changed

2 files changed

+15
-2
lines changed

gcc/cselib.cc

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1194,7 +1194,9 @@ cselib_redundant_set_p (rtx set)
11941194
if (cselib_reg_set_mode (dest) != GET_MODE (dest))
11951195
return false;
11961196

1197-
if (!rtx_equal_for_cselib_p (dest, SET_SRC (set)))
1197+
rtx src = SET_SRC (set);
1198+
if ((MEM_P (src) && MEM_VOLATILE_P (src))
1199+
|| !rtx_equal_for_cselib_p (dest, src))
11981200
return false;
11991201

12001202
while (GET_CODE (dest) == SUBREG
@@ -1205,6 +1207,9 @@ cselib_redundant_set_p (rtx set)
12051207
if (!flag_strict_aliasing || !MEM_P (dest))
12061208
return true;
12071209

1210+
if (MEM_VOLATILE_P (dest))
1211+
return false;
1212+
12081213
/* For a store we need to check that suppressing it will not change
12091214
the effective alias set. */
12101215
rtx dest_addr = XEXP (dest, 0);
@@ -1242,7 +1247,6 @@ cselib_redundant_set_p (rtx set)
12421247
/* We failed to find a recorded value in the cselib history, so try
12431248
the source of this set; this catches cases such as *p = *q when p
12441249
and q have the same value. */
1245-
rtx src = SET_SRC (set);
12461250
while (GET_CODE (src) == SUBREG)
12471251
src = XEXP (src, 0);
12481252

gcc/testsuite/gcc.dg/pr122343-1.c

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
/* { dg-do compile } */
2+
/* { dg-options "-O2 -fdump-rtl-final" } */
3+
/* { dg-final { scan-rtl-dump "\\\(mem/v:" "final" } } */
4+
5+
void
6+
foo (int *p)
7+
{
8+
*(volatile int *) p = *p;
9+
}

0 commit comments

Comments
 (0)