Skip to content

Commit

Permalink
InstCombine: Don't just copy known bits from the first operand of an …
Browse files Browse the repository at this point in the history
…srem.

That's obviously wrong. Conservatively restrict it to the sign bit, which
matches the original intention of this analysis. Fixes PR15940.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@181518 91177308-0d34-0410-b5e6-96231b3b80d8
  • Loading branch information
d0k committed May 9, 2013
1 parent 4fcf82f commit a6ff92a
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/Transforms/InstCombine/InstCombineSimplifyDemanded.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -754,7 +754,7 @@ Value *InstCombiner::SimplifyDemandedUseBits(Value *V, APInt DemandedMask,
ComputeMaskedBits(I->getOperand(0), LHSKnownZero, LHSKnownOne, Depth+1);
// If it's known zero, our sign bit is also zero.
if (LHSKnownZero.isNegative())
KnownZero |= LHSKnownZero;
KnownZero.setBit(KnownZero.getBitWidth() - 1);
}
break;
case Instruction::URem: {
Expand Down
12 changes: 12 additions & 0 deletions test/Transforms/InstCombine/icmp.ll
Original file line number Diff line number Diff line change
Expand Up @@ -707,6 +707,18 @@ define i1 @test69(i32 %c) nounwind uwtable {
ret i1 %3
}

; PR15940
; CHECK: @test70
; CHECK-NEXT: %A = srem i32 5, %X
; CHECK-NEXT: %C = icmp ne i32 %A, 2
; CHECK-NEXT: ret i1 %C
define i1 @test70(i32 %X) {
%A = srem i32 5, %X
%B = add i32 %A, 2
%C = icmp ne i32 %B, 4
ret i1 %C
}

; CHECK: @icmp_sext16trunc
; CHECK-NEXT: %1 = trunc i32 %x to i16
; CHECK-NEXT: %cmp = icmp slt i16 %1, 36
Expand Down

0 comments on commit a6ff92a

Please sign in to comment.