rdar://12329730 (2nd part, revised)
authorShuxin Yang <shuxin.llvm@gmail.com>
Tue, 4 Dec 2012 03:28:32 +0000 (03:28 +0000)
committerShuxin Yang <shuxin.llvm@gmail.com>
Tue, 4 Dec 2012 03:28:32 +0000 (03:28 +0000)
The type of shirt-right (logical or arithemetic) should remain unchanged
when transforming  "X << C1 >> C2" into "X << (C1-C2)"

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

lib/Transforms/InstCombine/InstCombineSimplifyDemanded.cpp
test/Transforms/InstCombine/shift.ll

index c65076e88312a2e2a0596cae282bba90f0c76a9f..c832ca5644a96a3a6a54e6bd38edd1d9c146b28a 100644 (file)
@@ -876,7 +876,8 @@ Value *InstCombiner::SimplifyShrShlDemandedBits(Instruction *Shr,
       New->setHasNoUnsignedWrap(Orig->hasNoUnsignedWrap());
     } else {
       Constant *Amt = ConstantInt::get(VarX->getType(), ShrAmt - ShlAmt);
-      New = BinaryOperator::CreateLShr(VarX, Amt);
+      New = isLshr ? BinaryOperator::CreateLShr(VarX, Amt) :
+                     BinaryOperator::CreateAShr(VarX, Amt);
     }
 
     return InsertNewInstWith(New, *Shl);
index b152816d2b7e3b12a20b27fb0248956055a03dc6..fad0bd7ede3fa1e8702ba02bc2177bef6c6d0a51 100644 (file)
@@ -723,7 +723,7 @@ define i32 @test60(i32 %x) {
   %or = or i32 %shl, 1
   ret i32 %or
 ; CHECK: @test60
-; CHECK: lshr i32 %x, 3
+; CHECK: ashr i32 %x, 3
 }