https://gcc.gnu.org/bugzilla/show_bug.cgi?id=127851

--- Comment #15 from Vineet Gupta <vineetg at gcc dot gnu.org> ---
Some updates:

The i386.md fix landed but the consensus was to do this in generic code anyways
as other targets could be affected (and there are PRs already to that effect).

Jeff wanted to see a more comprehensive fix.

> This would also seem to miss the case when the insn is not a single set,
> so maybe it's a PARALLEL with a bunch of reads/writes inside or other 
> forms that do not satisfy single_set.

[v4] posted addressed those.

This however still left a hole (as spotted by both Sashiko and Uros)

> Essentially the "succ == 0" check above implies this only happens for 
> I2 -> I3 combine, but leaves the 3 (or 4) combine cases broken. 
>
> e.g. Test below on x86, z is incorrectly read before y (with my v4 and
> despite Uroz's i386.md fix)
>
>  extern volatile int x, y, z;
>  int noarg (void) { int t1 = x; int t2 = y; int t3 = z; return t1 + t2 + t3; }

The issue was can_combine_p is only able to see the inputs which can miss any
ensuing splits (from failing to recog) and could re-introduce the reordering.

This leads to 2 approaches to solving it:
 - Do this check later, after any splits (with a pre-scan recording the
volatiles and their order).
 - Or check early: in try_combine (while I0..I3 are unaltered) and just refuse
to combine insns with more than one volatile memory reads.

The latter approach is much simpler and it what posted [v5] does.

[v5]
https://inbox.sourceware.org/gcc-patches/[email protected]/
[v4]
https://inbox.sourceware.org/gcc-patches/[email protected]/

Reply via email to