On Oct 24, 2006, at 9:45 PM, Reid Spencer wrote: > On Mon, 2006-10-23 at 22:52 -0700, Chris Lattner wrote: > >> I strongly recommend adding a transformation to instcombine that will >> produce more divs with such operands. For example, changing >> something >> like: >> >> %X = cast uint %A to int >> %Y = sdiv int %X, 1234 >> %Z = cast int %Y to uint >> into: >> %Z = sdiv uint %A, 1234 >> Fortunately, instcombine already does this for other operations >> (mul/add/and/or/xor, etc) at line 5658 of Instcombine in CVS. Please >> add a case there for UDIV/SDIV. This will hopefully help flush out >> bugs in the patch that I didn't catch. > > I took a look at doing this but there are corner cases I'm dealing > with. > If the input is: > > %X = cast uint %A to int > %Y = sdiv int %X, -1234 > %Z = cast int %Y to uint > > then its a little more challenging to make the sdiv work with unsigned > operands. So I'm assuming this only works with positive constants. > There are other corner cases too, like if the 2nd operand isn't a > constant but an instruction. > > I would rather not risk breaking things now by trying to add a new > transform. After implementing all your other suggestions the patch is > passing all the tests.
I don't follow. The existing code should transform this into: %Z = sdiv uint %A, 4294966062 This is exactly what you want. "4294966062" treated as a signed value (which is what sdiv does) is -1234. -Chris _______________________________________________ llvm-commits mailing list llvm-commits@cs.uiuc.edu http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits