|
|
4cbaf7 |
From 6674146ac94c8744c807ed06e1bdb99cef87b2fe Mon Sep 17 00:00:00 2001
|
|
|
4cbaf7 |
From: root <root@ibm-z10-50.rhts.eng.bos.redhat.com>
|
|
|
4cbaf7 |
Date: Fri, 14 Apr 2017 16:06:58 -0400
|
|
|
4cbaf7 |
Subject: [PATCH] Revert "[InstCombine] transform bitcasted bitwise logic ops
|
|
|
4cbaf7 |
with constants (PR26702)"
|
|
|
4cbaf7 |
|
|
|
4cbaf7 |
This reverts commit 76b12c4bf0bbc5c70def7b5d083a8a70547ea4e3.
|
|
|
4cbaf7 |
|
|
|
4cbaf7 |
Conflicts:
|
|
|
4cbaf7 |
lib/Transforms/InstCombine/InstCombineAndOrXor.cpp
|
|
|
4cbaf7 |
---
|
|
|
4cbaf7 |
lib/Transforms/InstCombine/InstCombineAndOrXor.cpp | 34 +++++-----------------
|
|
|
4cbaf7 |
test/Transforms/InstCombine/bitcast-bigendian.ll | 14 +++++----
|
|
|
4cbaf7 |
test/Transforms/InstCombine/bitcast.ll | 14 +++++----
|
|
|
4cbaf7 |
3 files changed, 23 insertions(+), 39 deletions(-)
|
|
|
4cbaf7 |
|
|
|
4cbaf7 |
diff --git a/lib/Transforms/InstCombine/InstCombineAndOrXor.cpp b/lib/Transforms/InstCombine/InstCombineAndOrXor.cpp
|
|
|
4cbaf7 |
index 1a6459b..36c2136 100644
|
|
|
4cbaf7 |
--- a/lib/Transforms/InstCombine/InstCombineAndOrXor.cpp
|
|
|
4cbaf7 |
+++ b/lib/Transforms/InstCombine/InstCombineAndOrXor.cpp
|
|
|
4cbaf7 |
@@ -1201,41 +1201,21 @@ Instruction *InstCombiner::foldCastedBitwiseLogic(BinaryOperator &I) {
|
|
|
4cbaf7 |
|
|
|
4cbaf7 |
Value *Op0 = I.getOperand(0), *Op1 = I.getOperand(1);
|
|
|
4cbaf7 |
CastInst *Cast0 = dyn_cast<CastInst>(Op0);
|
|
|
4cbaf7 |
- if (!Cast0)
|
|
|
4cbaf7 |
- return nullptr;
|
|
|
4cbaf7 |
-
|
|
|
4cbaf7 |
- // This must be a cast from an integer or integer vector source type to allow
|
|
|
4cbaf7 |
- // transformation of the logic operation to the source type.
|
|
|
4cbaf7 |
- Type *DestTy = I.getType();
|
|
|
4cbaf7 |
- Type *SrcTy = Cast0->getSrcTy();
|
|
|
4cbaf7 |
- if (!SrcTy->isIntOrIntVectorTy())
|
|
|
4cbaf7 |
- return nullptr;
|
|
|
4cbaf7 |
-
|
|
|
4cbaf7 |
- // If one operand is a bitcast and the other is a constant, move the logic
|
|
|
4cbaf7 |
- // operation ahead of the bitcast. That is, do the logic operation in the
|
|
|
4cbaf7 |
- // original type. This can eliminate useless bitcasts and allow normal
|
|
|
4cbaf7 |
- // combines that would otherwise be impeded by the bitcast. Canonicalization
|
|
|
4cbaf7 |
- // ensures that if there is a constant operand, it will be the second operand.
|
|
|
4cbaf7 |
- Value *BC = nullptr;
|
|
|
4cbaf7 |
- Constant *C = nullptr;
|
|
|
4cbaf7 |
- if ((match(Op0, m_BitCast(m_Value(BC))) && match(Op1, m_Constant(C)))) {
|
|
|
4cbaf7 |
- Value *NewConstant = ConstantExpr::getBitCast(C, SrcTy);
|
|
|
4cbaf7 |
- Value *NewOp = Builder->CreateBinOp(LogicOpc, BC, NewConstant, I.getName());
|
|
|
4cbaf7 |
- return CastInst::CreateBitOrPointerCast(NewOp, DestTy);
|
|
|
4cbaf7 |
- }
|
|
|
4cbaf7 |
-
|
|
|
4cbaf7 |
CastInst *Cast1 = dyn_cast<CastInst>(Op1);
|
|
|
4cbaf7 |
- if (!Cast1)
|
|
|
4cbaf7 |
+ if (!Cast0 || !Cast1)
|
|
|
4cbaf7 |
return nullptr;
|
|
|
4cbaf7 |
|
|
|
4cbaf7 |
- // Both operands of the logic operation are casts. The casts must be of the
|
|
|
4cbaf7 |
- // same type for reduction.
|
|
|
4cbaf7 |
+ // The casts must be of the same type, and this must be a cast from an integer
|
|
|
4cbaf7 |
+ // or integer vector source type.
|
|
|
4cbaf7 |
auto CastOpcode = Cast0->getOpcode();
|
|
|
4cbaf7 |
- if (CastOpcode != Cast1->getOpcode() || SrcTy != Cast1->getSrcTy())
|
|
|
4cbaf7 |
+ Type *SrcTy = Cast0->getSrcTy();
|
|
|
4cbaf7 |
+ if ((CastOpcode != Cast1->getOpcode()) || (SrcTy != Cast1->getSrcTy()) ||
|
|
|
4cbaf7 |
+ !SrcTy->isIntOrIntVectorTy())
|
|
|
4cbaf7 |
return nullptr;
|
|
|
4cbaf7 |
|
|
|
4cbaf7 |
Value *Cast0Src = Cast0->getOperand(0);
|
|
|
4cbaf7 |
Value *Cast1Src = Cast1->getOperand(0);
|
|
|
4cbaf7 |
+ Type *DestTy = I.getType();
|
|
|
4cbaf7 |
|
|
|
4cbaf7 |
// fold (logic (cast A), (cast B)) -> (cast (logic A, B))
|
|
|
4cbaf7 |
|
|
|
4cbaf7 |
diff --git a/test/Transforms/InstCombine/bitcast-bigendian.ll b/test/Transforms/InstCombine/bitcast-bigendian.ll
|
|
|
4cbaf7 |
index f558ecc..4042dad 100644
|
|
|
4cbaf7 |
--- a/test/Transforms/InstCombine/bitcast-bigendian.ll
|
|
|
4cbaf7 |
+++ b/test/Transforms/InstCombine/bitcast-bigendian.ll
|
|
|
4cbaf7 |
@@ -90,6 +90,8 @@ define <2 x float> @test6(float %A){
|
|
|
4cbaf7 |
; CHECK: ret
|
|
|
4cbaf7 |
}
|
|
|
4cbaf7 |
|
|
|
4cbaf7 |
+; FIXME: Do the logic in the original type for the following 3 tests.
|
|
|
4cbaf7 |
+
|
|
|
4cbaf7 |
; Verify that 'xor' of vector and constant is done as a vector bitwise op before the bitcast.
|
|
|
4cbaf7 |
|
|
|
4cbaf7 |
define <2 x i32> @xor_bitcast_vec_to_vec(<1 x i64> %a) {
|
|
|
4cbaf7 |
@@ -98,8 +100,8 @@ define <2 x i32> @xor_bitcast_vec_to_vec(<1 x i64> %a) {
|
|
|
4cbaf7 |
ret <2 x i32> %t2
|
|
|
4cbaf7 |
|
|
|
4cbaf7 |
; CHECK-LABEL: @xor_bitcast_vec_to_vec(
|
|
|
4cbaf7 |
-; CHECK-NEXT: %t21 = xor <1 x i64> %a, <i64 4294967298>
|
|
|
4cbaf7 |
-; CHECK-NEXT: %t2 = bitcast <1 x i64> %t21 to <2 x i32>
|
|
|
4cbaf7 |
+; CHECK-NEXT: %t1 = bitcast <1 x i64> %a to <2 x i32>
|
|
|
4cbaf7 |
+; CHECK-NEXT: %t2 = xor <2 x i32> %t1, <i32 1, i32 2>
|
|
|
4cbaf7 |
; CHECK-NEXT: ret <2 x i32> %t2
|
|
|
4cbaf7 |
}
|
|
|
4cbaf7 |
|
|
|
4cbaf7 |
@@ -111,8 +113,8 @@ define i64 @and_bitcast_vec_to_int(<2 x i32> %a) {
|
|
|
4cbaf7 |
ret i64 %t2
|
|
|
4cbaf7 |
|
|
|
4cbaf7 |
; CHECK-LABEL: @and_bitcast_vec_to_int(
|
|
|
4cbaf7 |
-; CHECK-NEXT: %t21 = and <2 x i32> %a, <i32 0, i32 3>
|
|
|
4cbaf7 |
-; CHECK-NEXT: %t2 = bitcast <2 x i32> %t21 to i64
|
|
|
4cbaf7 |
+; CHECK-NEXT: %t1 = bitcast <2 x i32> %a to i64
|
|
|
4cbaf7 |
+; CHECK-NEXT: %t2 = and i64 %t1, 3
|
|
|
4cbaf7 |
; CHECK-NEXT: ret i64 %t2
|
|
|
4cbaf7 |
}
|
|
|
4cbaf7 |
|
|
|
4cbaf7 |
@@ -124,8 +126,8 @@ define <2 x i32> @or_bitcast_int_to_vec(i64 %a) {
|
|
|
4cbaf7 |
ret <2 x i32> %t2
|
|
|
4cbaf7 |
|
|
|
4cbaf7 |
; CHECK-LABEL: @or_bitcast_int_to_vec(
|
|
|
4cbaf7 |
-; CHECK-NEXT: %t21 = or i64 %a, 4294967298
|
|
|
4cbaf7 |
-; CHECK-NEXT: %t2 = bitcast i64 %t21 to <2 x i32>
|
|
|
4cbaf7 |
+; CHECK-NEXT: %t1 = bitcast i64 %a to <2 x i32>
|
|
|
4cbaf7 |
+; CHECK-NEXT: %t2 = or <2 x i32> %t1, <i32 1, i32 2>
|
|
|
4cbaf7 |
; CHECK-NEXT: ret <2 x i32> %t2
|
|
|
4cbaf7 |
}
|
|
|
4cbaf7 |
|
|
|
4cbaf7 |
diff --git a/test/Transforms/InstCombine/bitcast.ll b/test/Transforms/InstCombine/bitcast.ll
|
|
|
4cbaf7 |
index 7495859..34e9206 100644
|
|
|
4cbaf7 |
--- a/test/Transforms/InstCombine/bitcast.ll
|
|
|
4cbaf7 |
+++ b/test/Transforms/InstCombine/bitcast.ll
|
|
|
4cbaf7 |
@@ -30,6 +30,8 @@ define <2 x i32> @xor_two_vector_bitcasts(<1 x i64> %a, <1 x i64> %b) {
|
|
|
4cbaf7 |
; CHECK-NEXT: ret <2 x i32> %t3
|
|
|
4cbaf7 |
}
|
|
|
4cbaf7 |
|
|
|
4cbaf7 |
+; FIXME: Do the logic in the original type for the following 3 tests.
|
|
|
4cbaf7 |
+
|
|
|
4cbaf7 |
; Verify that 'xor' of vector and constant is done as a vector bitwise op before the bitcast.
|
|
|
4cbaf7 |
|
|
|
4cbaf7 |
define <2 x i32> @xor_bitcast_vec_to_vec(<1 x i64> %a) {
|
|
|
4cbaf7 |
@@ -38,8 +40,8 @@ define <2 x i32> @xor_bitcast_vec_to_vec(<1 x i64> %a) {
|
|
|
4cbaf7 |
ret <2 x i32> %t2
|
|
|
4cbaf7 |
|
|
|
4cbaf7 |
; CHECK-LABEL: @xor_bitcast_vec_to_vec(
|
|
|
4cbaf7 |
-; CHECK-NEXT: %t21 = xor <1 x i64> %a, <i64 8589934593>
|
|
|
4cbaf7 |
-; CHECK-NEXT: %t2 = bitcast <1 x i64> %t21 to <2 x i32>
|
|
|
4cbaf7 |
+; CHECK-NEXT: %t1 = bitcast <1 x i64> %a to <2 x i32>
|
|
|
4cbaf7 |
+; CHECK-NEXT: %t2 = xor <2 x i32> %t1, <i32 1, i32 2>
|
|
|
4cbaf7 |
; CHECK-NEXT: ret <2 x i32> %t2
|
|
|
4cbaf7 |
}
|
|
|
4cbaf7 |
|
|
|
4cbaf7 |
@@ -51,8 +53,8 @@ define i64 @and_bitcast_vec_to_int(<2 x i32> %a) {
|
|
|
4cbaf7 |
ret i64 %t2
|
|
|
4cbaf7 |
|
|
|
4cbaf7 |
; CHECK-LABEL: @and_bitcast_vec_to_int(
|
|
|
4cbaf7 |
-; CHECK-NEXT: %t21 = and <2 x i32> %a, <i32 3, i32 0>
|
|
|
4cbaf7 |
-; CHECK-NEXT: %t2 = bitcast <2 x i32> %t21 to i64
|
|
|
4cbaf7 |
+; CHECK-NEXT: %t1 = bitcast <2 x i32> %a to i64
|
|
|
4cbaf7 |
+; CHECK-NEXT: %t2 = and i64 %t1, 3
|
|
|
4cbaf7 |
; CHECK-NEXT: ret i64 %t2
|
|
|
4cbaf7 |
}
|
|
|
4cbaf7 |
|
|
|
4cbaf7 |
@@ -64,8 +66,8 @@ define <2 x i32> @or_bitcast_int_to_vec(i64 %a) {
|
|
|
4cbaf7 |
ret <2 x i32> %t2
|
|
|
4cbaf7 |
|
|
|
4cbaf7 |
; CHECK-LABEL: @or_bitcast_int_to_vec(
|
|
|
4cbaf7 |
-; CHECK-NEXT: %t21 = or i64 %a, 8589934593
|
|
|
4cbaf7 |
-; CHECK-NEXT: %t2 = bitcast i64 %t21 to <2 x i32>
|
|
|
4cbaf7 |
+; CHECK-NEXT: %t1 = bitcast i64 %a to <2 x i32>
|
|
|
4cbaf7 |
+; CHECK-NEXT: %t2 = or <2 x i32> %t1, <i32 1, i32 2>
|
|
|
4cbaf7 |
; CHECK-NEXT: ret <2 x i32> %t2
|
|
|
4cbaf7 |
}
|
|
|
4cbaf7 |
|
|
|
4cbaf7 |
--
|
|
|
4cbaf7 |
1.8.3.1
|
|
|
4cbaf7 |
|