implement cast.ll:test35. With this, we recognize:
authorChris Lattner <sabre@nondot.org>
Wed, 29 Nov 2006 07:18:39 +0000 (07:18 +0000)
committerChris Lattner <sabre@nondot.org>
Wed, 29 Nov 2006 07:18:39 +0000 (07:18 +0000)
unsigned short swp(unsigned short a) {
       return ((a & 0xff00) >> 8 | (a & 0x00ff) << 8);
}

as an idiom for bswap.

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

lib/Transforms/Scalar/InstructionCombining.cpp

index a5bf60bdeb5c9f07e9319e2d4c749aeaf872252f..f20d0dd21abc8f8045f91a0e08474063e1ecbf72 100644 (file)
@@ -5624,6 +5624,14 @@ static bool CanEvaluateInDifferentType(Value *V, const Type *Ty,
     // 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 @@ Value *InstCombiner::EvaluateInDifferentType(Value *V, const Type *Ty) {
                                  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: