ComputeMaskedBits: sub falls through to add, and sub doesn't have the same overflow...
authorBenjamin Kramer <benny.kra@googlemail.com>
Fri, 11 Mar 2011 14:46:49 +0000 (14:46 +0000)
committerBenjamin Kramer <benny.kra@googlemail.com>
Fri, 11 Mar 2011 14:46:49 +0000 (14:46 +0000)
Should fix the selfhost failures that started with r127463.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@127465 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Analysis/ValueTracking.cpp
test/Transforms/InstCombine/sext.ll

index 33fb1e8cdc8a21b9428ae912332f8b4add22a7c1..6c33d2d508e3167f29cfc61df6abbaca2798eb58 100644 (file)
@@ -431,7 +431,8 @@ void llvm::ComputeMaskedBits(Value *V, const APInt &Mask,
     }
 
     // Are we still trying to solve for the sign bit?
-    if (Mask.isNegative() && !KnownZero.isNegative() && !KnownOne.isNegative()){
+    if (I->getOpcode() == Instruction::Add &&
+        Mask.isNegative() && !KnownZero.isNegative() && !KnownOne.isNegative()){
       OverflowingBinaryOperator *OBO = cast<OverflowingBinaryOperator>(I);
       if (OBO->hasNoSignedWrap()) {
         // Adding two positive numbers can't wrap into negative ...
index 60669b7a109f45bb85bcd71eb64182157b4ba2ba..da52d92695275ef6d096b4b1f68277d06079f566 100644 (file)
@@ -126,3 +126,13 @@ define void @test11(<2 x i16> %srcA, <2 x i16> %srcB, <2 x i16>* %dst) {
 ; CHECK-NEXT: store <2 x i16>
 ; CHECK-NEXT: ret
 }                                                                                                                               
+
+define i64 @test12(i32 %x) nounwind {
+  %shr = lshr i32 %x, 1
+  %sub = sub nsw i32 0, %shr
+  %conv = sext i32 %sub to i64
+  ret i64 %conv
+; CHECK: @test12
+; CHECK: sext
+; CHECK: ret
+}