]> granicus.if.org Git - llvm/commitdiff
[InstCombine] Support BITWISE_OP(BSWAP(A),BSWAP(B))->BSWAP(BITWISE_OP(A, B)) for...
authorCraig Topper <craig.topper@intel.com>
Mon, 3 Jul 2017 05:54:13 +0000 (05:54 +0000)
committerCraig Topper <craig.topper@intel.com>
Mon, 3 Jul 2017 05:54:13 +0000 (05:54 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@306999 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Transforms/InstCombine/InstCombineAndOrXor.cpp
test/Transforms/InstCombine/bswap-fold.ll

index cb3f3214e99c69adfde553d503f5b8a59f2ea8b4..9a6199fdafba7479eb076aef5fbc24a3010a5022 100644 (file)
@@ -82,12 +82,7 @@ static Value *getFCmpValue(unsigned Code, Value *LHS, Value *RHS,
 Value *InstCombiner::SimplifyBSwap(BinaryOperator &I) {
   assert(I.isBitwiseLogicOp() && "Unexpected opcode for bswap simplifying");
 
-  IntegerType *ITy = dyn_cast<IntegerType>(I.getType());
-
-  // Can't do vectors.
-  if (I.getType()->isVectorTy())
-    return nullptr;
-
+  // TODO handle constant on one side with vectors.
   Value *OldLHS = I.getOperand(0);
   Value *OldRHS = I.getOperand(1);
   ConstantInt *ConstLHS = dyn_cast<ConstantInt>(OldLHS);
@@ -115,7 +110,8 @@ Value *InstCombiner::SimplifyBSwap(BinaryOperator &I) {
                   Builder->getInt(ConstRHS->getValue().byteSwap());
 
   Value *BinOp = Builder->CreateBinOp(I.getOpcode(), NewLHS, NewRHS);
-  Function *F = Intrinsic::getDeclaration(I.getModule(), Intrinsic::bswap, ITy);
+  Function *F = Intrinsic::getDeclaration(I.getModule(), Intrinsic::bswap,
+                                          I.getType());
   return Builder->CreateCall(F, BinOp);
 }
 
index cc947bad2336f031576996f1a477e926e73d9129..3edd7b338ae41bdd204f63b78191dfcebf95bf19 100644 (file)
@@ -213,10 +213,9 @@ define i64 @bs_xor64(i64 %a, i64 %b) #0 {
 
 define <2 x i32> @bs_and32vec(<2 x i32> %a, <2 x i32> %b) #0 {
 ; CHECK-LABEL: @bs_and32vec(
-; CHECK-NEXT:    [[TMP1:%.*]] = tail call <2 x i32> @llvm.bswap.v2i32(<2 x i32> [[A:%.*]])
-; CHECK-NEXT:    [[TMP2:%.*]] = tail call <2 x i32> @llvm.bswap.v2i32(<2 x i32> [[B:%.*]])
-; CHECK-NEXT:    [[TMP3:%.*]] = and <2 x i32> [[TMP1]], [[TMP2]]
-; CHECK-NEXT:    ret <2 x i32> [[TMP3]]
+; CHECK-NEXT:    [[TMP1:%.*]] = and <2 x i32> [[A:%.*]], [[B:%.*]]
+; CHECK-NEXT:    [[TMP2:%.*]] = call <2 x i32> @llvm.bswap.v2i32(<2 x i32> [[TMP1]])
+; CHECK-NEXT:    ret <2 x i32> [[TMP2]]
 ;
   %tmp1 = tail call <2 x i32> @llvm.bswap.v2i32(<2 x i32> %a)
   %tmp2 = tail call <2 x i32> @llvm.bswap.v2i32(<2 x i32> %b)
@@ -226,10 +225,9 @@ define <2 x i32> @bs_and32vec(<2 x i32> %a, <2 x i32> %b) #0 {
 
 define <2 x i32> @bs_or32vec(<2 x i32> %a, <2 x i32> %b) #0 {
 ; CHECK-LABEL: @bs_or32vec(
-; CHECK-NEXT:    [[TMP1:%.*]] = tail call <2 x i32> @llvm.bswap.v2i32(<2 x i32> [[A:%.*]])
-; CHECK-NEXT:    [[TMP2:%.*]] = tail call <2 x i32> @llvm.bswap.v2i32(<2 x i32> [[B:%.*]])
-; CHECK-NEXT:    [[TMP3:%.*]] = or <2 x i32> [[TMP1]], [[TMP2]]
-; CHECK-NEXT:    ret <2 x i32> [[TMP3]]
+; CHECK-NEXT:    [[TMP1:%.*]] = or <2 x i32> [[A:%.*]], [[B:%.*]]
+; CHECK-NEXT:    [[TMP2:%.*]] = call <2 x i32> @llvm.bswap.v2i32(<2 x i32> [[TMP1]])
+; CHECK-NEXT:    ret <2 x i32> [[TMP2]]
 ;
   %tmp1 = tail call <2 x i32> @llvm.bswap.v2i32(<2 x i32> %a)
   %tmp2 = tail call <2 x i32> @llvm.bswap.v2i32(<2 x i32> %b)
@@ -239,10 +237,9 @@ define <2 x i32> @bs_or32vec(<2 x i32> %a, <2 x i32> %b) #0 {
 
 define <2 x i32> @bs_xor32vec(<2 x i32> %a, <2 x i32> %b) #0 {
 ; CHECK-LABEL: @bs_xor32vec(
-; CHECK-NEXT:    [[TMP1:%.*]] = tail call <2 x i32> @llvm.bswap.v2i32(<2 x i32> [[A:%.*]])
-; CHECK-NEXT:    [[TMP2:%.*]] = tail call <2 x i32> @llvm.bswap.v2i32(<2 x i32> [[B:%.*]])
-; CHECK-NEXT:    [[TMP3:%.*]] = xor <2 x i32> [[TMP1]], [[TMP2]]
-; CHECK-NEXT:    ret <2 x i32> [[TMP3]]
+; CHECK-NEXT:    [[TMP1:%.*]] = xor <2 x i32> [[A:%.*]], [[B:%.*]]
+; CHECK-NEXT:    [[TMP2:%.*]] = call <2 x i32> @llvm.bswap.v2i32(<2 x i32> [[TMP1]])
+; CHECK-NEXT:    ret <2 x i32> [[TMP2]]
 ;
   %tmp1 = tail call <2 x i32> @llvm.bswap.v2i32(<2 x i32> %a)
   %tmp2 = tail call <2 x i32> @llvm.bswap.v2i32(<2 x i32> %b)