On Tue, Jan 16, 2007 at 01:31:06PM -0800, David Daney wrote: > Andrew Haley wrote: > >Ian Lance Taylor writes: > > > I suspect that the best fix, in the sense of generating the best > > > code, would be to do this at the tree level. That will give loop > > > and VRP optimizations the best chance to eliminate the test for -1. > > > Doing it during gimplification would be easy, if perhaps rather > > > ugly. If there are indeed several processors with this oddity, > > > then it would even make a certain degree of sense as a > > > target-independent option. > > > >x86, x86-64, S/390, as far as I'm aware. > > > > MIPS does *not* seem to suffer from this 'defect', so a target > independent solution that caused MIPS to generate worse code would be bad.
Since at least three targets are affected, it would seem that doing it at the tree level is the right thing. The tree level code could consult a flag saying whether to jump through hoops to avoid faulting for i % -1. This flag would never be set for the MIPS, and would be set for x86, x86-64, or S/390 only if the user asks for it. If the flag is present, the operation would be treat i % j as either (j == -1 ? 0 : i rem j) or (i % abs(j)) or whatever other expression might yield the best code.