[LLVMbugs] [Bug 21256] New: InstCombine: 'X % -Y -> X % Y' incorrect if Y < 0

bugzilla-daemon at llvm.org bugzilla-daemon at llvm.org
Mon Oct 13 03:16:57 PDT 2014


            Bug ID: 21256
           Summary: InstCombine: 'X % -Y -> X % Y' incorrect if Y < 0
           Product: libraries
           Version: trunk
          Hardware: All
                OS: All
            Status: NEW
          Severity: normal
          Priority: P
         Component: Scalar Optimizations
          Assignee: unassignedbugs at nondot.org
          Reporter: nunoplopes at sapo.pt
                CC: llvmbugs at cs.uiuc.edu
    Classification: Unclassified

In InstCombiner::visitSRem(), the transformation 'X % -Y -> X % Y' should be
applied only to constants, since we don't know what's the value of Y if it's
not a constant and we could be introducing undefined behavior.

  if (Value *RHSNeg = dyn_castNegVal(Op1))
    if (!isa<Constant>(RHSNeg) ||
        (isa<ConstantInt>(RHSNeg) &&
         cast<ConstantInt>(RHSNeg)->getValue().isStrictlyPositive())) {
      // X % -Y -> X % Y
      I.setOperand(1, RHSNeg);
      return &I;

I propose we drop the '!isa<Constant>(RHSNeg) ||' part.

This is what Alive says:

%Op1 = sub 0, %X
%r = srem %Op0, %Op1
%r = srem %Op0, %X

ERROR: Domain of definedness of Target is smaller than Source's for i4 %r

%X i4 = 0xF (15, -1)
%Op0 i4 = 0x8 (8, -8)
%Op1 i4 = 0x1 (1)
Source value: 0x0 (0)
Target value: undef

You are receiving this mail because:
You are on the CC list for the bug.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-bugs/attachments/20141013/6cfad695/attachment.html>

More information about the llvm-bugs mailing list