* [patch] Fix PR rtl-optimization/102306
@ 2021-09-16 9:02 Eric Botcazou
2021-09-16 15:22 ` Jeff Law
0 siblings, 1 reply; 2+ messages in thread
From: Eric Botcazou @ 2021-09-16 9:02 UTC (permalink / raw)
To: gcc-patches
[-- Attachment #1: Type: text/plain, Size: 844 bytes --]
Hi,
this is a duplication of volatile loads introduced during GCC 9 development by
the new 2->2 mechanism of the RTL combiner. There is already a substantial
checking for volatile references in can_combine_p but it implicitly assumes
that the combination reduces the number of instructions, which is of course
not the case here. So the fix teaches try_combine to abort the combination
when it is about to make a copy of volatile references to preserve them.
Bootstrapped/regtested on x86-64/Linux, OK for mainline and release branches?
2021-09-16 Eric Botcazou <ebotcazou@adacore.com>
PR rtl-optimization/102306
* combine.c (try_combine): Abort the combination if we are about
to duplicate volatile references.
2021-09-16 Eric Botcazou <ebotcazou@adacore.com>
* gcc.target/sparc/20210916-1.c: New test.
--
Eric Botcazou
[-- Attachment #2: pr102306.diff --]
[-- Type: text/x-patch, Size: 686 bytes --]
diff --git a/gcc/combine.c b/gcc/combine.c
index 290a3667c65..892c834a160 100644
--- a/gcc/combine.c
+++ b/gcc/combine.c
@@ -3063,6 +3063,16 @@ try_combine (rtx_insn *i3, rtx_insn *i2, rtx_insn *i1, rtx_insn *i0,
return 0;
}
+ /* We cannot safely duplicate volatile references in any case. */
+
+ if ((added_sets_2 && volatile_refs_p (PATTERN (i2)))
+ || (added_sets_1 && volatile_refs_p (PATTERN (i1)))
+ || (added_sets_0 && volatile_refs_p (PATTERN (i0))))
+ {
+ undo_all ();
+ return 0;
+ }
+
/* Count how many auto_inc expressions there were in the original insns;
we need to have the same number in the resulting patterns. */
[-- Attachment #3: 20210916-1.c --]
[-- Type: text/x-csrc, Size: 289 bytes --]
/* { dg-do compile } */
/* { dg-require-effective-target ilp32 } */
/* { dg-options "-O -mcpu=v8" } */
extern void foo (void);
void test (volatile unsigned char *a)
{
char b = *a;
if (!b)
return;
if (b & 2)
foo ();
}
/* { dg-final { scan-assembler-times "ldub" 1 } } */
^ permalink raw reply [flat|nested] 2+ messages in thread
* Re: [patch] Fix PR rtl-optimization/102306
2021-09-16 9:02 [patch] Fix PR rtl-optimization/102306 Eric Botcazou
@ 2021-09-16 15:22 ` Jeff Law
0 siblings, 0 replies; 2+ messages in thread
From: Jeff Law @ 2021-09-16 15:22 UTC (permalink / raw)
To: Eric Botcazou, gcc-patches
On 9/16/2021 3:02 AM, Eric Botcazou wrote:
> Hi,
>
> this is a duplication of volatile loads introduced during GCC 9 development by
> the new 2->2 mechanism of the RTL combiner. There is already a substantial
> checking for volatile references in can_combine_p but it implicitly assumes
> that the combination reduces the number of instructions, which is of course
> not the case here. So the fix teaches try_combine to abort the combination
> when it is about to make a copy of volatile references to preserve them.
>
> Bootstrapped/regtested on x86-64/Linux, OK for mainline and release branches?
>
>
> 2021-09-16 Eric Botcazou <ebotcazou@adacore.com>
>
> PR rtl-optimization/102306
> * combine.c (try_combine): Abort the combination if we are about
> to duplicate volatile references.
>
>
> 2021-09-16 Eric Botcazou <ebotcazou@adacore.com>
>
> * gcc.target/sparc/20210916-1.c: New test.
OK
jeff
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2021-09-16 15:22 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-09-16 9:02 [patch] Fix PR rtl-optimization/102306 Eric Botcazou
2021-09-16 15:22 ` Jeff Law
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).