[llvm-commits] [llvm] r93128 - in /llvm/trunk: lib/Transforms/InstCombine/InstCombineCasts.cpp test/Transforms/InstCombine/cast.ll

Chris Lattner sabre at nondot.org
Sun Jan 10 12:30:41 PST 2010


Author: lattner
Date: Sun Jan 10 14:30:41 2010
New Revision: 93128

URL: http://llvm.org/viewvc/llvm-project?rev=93128&view=rev
Log:
teach sext optimization to handle truncs from types that are not
the dest of the sext.

Modified:
    llvm/trunk/lib/Transforms/InstCombine/InstCombineCasts.cpp
    llvm/trunk/test/Transforms/InstCombine/cast.ll

Modified: llvm/trunk/lib/Transforms/InstCombine/InstCombineCasts.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Transforms/InstCombine/InstCombineCasts.cpp?rev=93128&r1=93127&r2=93128&view=diff

==============================================================================
--- llvm/trunk/lib/Transforms/InstCombine/InstCombineCasts.cpp (original)
+++ llvm/trunk/lib/Transforms/InstCombine/InstCombineCasts.cpp Sun Jan 10 14:30:41 2010
@@ -799,6 +799,10 @@
   if (!I->hasOneUse()) return false;
 
   switch (I->getOpcode()) {
+  case Instruction::SExt:  // sext(sext(x)) -> sext(x)
+  case Instruction::ZExt:  // sext(zext(x)) -> zext(x)
+  case Instruction::Trunc: // sext(trunc(x)) -> trunc(x) or sext(x)
+    return true;
   case Instruction::And:
   case Instruction::Or:
   case Instruction::Xor:
@@ -813,9 +817,6 @@
   //case Instruction::LShr:  TODO
   //case Instruction::Trunc: TODO
       
-  case Instruction::SExt: // sext(sext(x)) -> sext(x)
-  case Instruction::ZExt: // sext(zext(x)) -> zext(x)
-    return true;
   case Instruction::Select:
     return CanEvaluateSExtd(I->getOperand(1), Ty, TD) &&
            CanEvaluateSExtd(I->getOperand(2), Ty, TD);

Modified: llvm/trunk/test/Transforms/InstCombine/cast.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Transforms/InstCombine/cast.ll?rev=93128&r1=93127&r2=93128&view=diff

==============================================================================
--- llvm/trunk/test/Transforms/InstCombine/cast.ll (original)
+++ llvm/trunk/test/Transforms/InstCombine/cast.ll Sun Jan 10 14:30:41 2010
@@ -523,3 +523,29 @@
 ; CHECK-NEXT: %D = and i64 %C, 40186
 ; CHECK-NEXT: ret i64 %D
 }
+
+define i32 @test54(i64 %A) {
+  %B = trunc i64 %A to i16
+  %C = or i16 %B, -32574
+  %D = and i16 %C, -25350
+  %E = sext i16 %D to i32
+  ret i32 %E
+; CHECK: @test54
+; CHECK-NEXT: %B = trunc i64 %A to i32
+; CHECK-NEXT: %C = or i32 %B, -32574
+; CHECK-NEXT: %D = and i32 %C, -25350
+; CHECK-NEXT: ret i32 %D
+}
+
+define i64 @test55(i32 %A) {
+  %B = trunc i32 %A to i16
+  %C = or i16 %B, -32574
+  %D = and i16 %C, -25350
+  %E = sext i16 %D to i64
+  ret i64 %E
+; CHECK: @test55
+; CHECK-NEXT: %B = zext i32 %A to i64
+; CHECK-NEXT: %C = or i64 %B, -32574
+; CHECK-NEXT: %D = and i64 %C, -25350
+; CHECK-NEXT: ret i64 %D
+}
\ No newline at end of file





More information about the llvm-commits mailing list