[llvm-commits] CVS: llvm/lib/Transforms/Scalar/InstructionCombining.cpp

Chris Lattner sabre at nondot.org
Tue Nov 28 23:18:53 PST 2006



Changes in directory llvm/lib/Transforms/Scalar:

InstructionCombining.cpp updated: 1.554 -> 1.555
---
Log message:

implement cast.ll:test35.  With this, we recognize:

unsigned short swp(unsigned short a) {
       return ((a & 0xff00) >> 8 | (a & 0x00ff) << 8);
}

as an idiom for bswap.



---
Diffs of the changes:  (+16 -0)

 InstructionCombining.cpp |   16 ++++++++++++++++
 1 files changed, 16 insertions(+)


Index: llvm/lib/Transforms/Scalar/InstructionCombining.cpp
diff -u llvm/lib/Transforms/Scalar/InstructionCombining.cpp:1.554 llvm/lib/Transforms/Scalar/InstructionCombining.cpp:1.555
--- llvm/lib/Transforms/Scalar/InstructionCombining.cpp:1.554	Wed Nov 29 01:04:07 2006
+++ llvm/lib/Transforms/Scalar/InstructionCombining.cpp	Wed Nov 29 01:18:39 2006
@@ -5624,6 +5624,14 @@
     // These operators can all arbitrarily be extended or truncated.
     return CanEvaluateInDifferentType(I->getOperand(0), Ty, NumCastsRemoved) &&
            CanEvaluateInDifferentType(I->getOperand(1), Ty, NumCastsRemoved);
+  case Instruction::AShr:
+  case Instruction::LShr:
+  case Instruction::Shl:
+    // If this is just a bitcast changing the sign of the operation, we can
+    // convert if the operand can be converted.
+    if (V->getType()->getPrimitiveSizeInBits() == Ty->getPrimitiveSizeInBits())
+      return CanEvaluateInDifferentType(I->getOperand(0), Ty, NumCastsRemoved);
+    break;
   case Instruction::Trunc:
   case Instruction::ZExt:
   case Instruction::SExt:
@@ -5669,6 +5677,14 @@
                                  LHS, RHS, I->getName());
     break;
   }
+  case Instruction::AShr:
+  case Instruction::LShr:
+  case Instruction::Shl: {
+    Value *LHS = EvaluateInDifferentType(I->getOperand(0), Ty);
+    Res = new ShiftInst((Instruction::OtherOps)I->getOpcode(), LHS,
+                        I->getOperand(1), I->getName());
+    break;
+  }    
   case Instruction::Trunc:
   case Instruction::ZExt:
   case Instruction::SExt:






More information about the llvm-commits mailing list