Skip to content
This repository was archived by the owner on Apr 23, 2020. It is now read-only.

Commit 1bc52fb

Browse files
committed
[InstCombine] Remove check for sext of vector icmp from shouldOptimizeCast
Looks like for 'and' and 'or' we end up performing at least some of the transformations this is bocking in a round about way anyway. For 'and sext(cmp1), sext(cmp2) we end up later turning it into 'select cmp1, sext(cmp2), 0'. Then we optimize that back to sext (and cmp1, cmp2). This is the same result we would have gotten if shouldOptimizeCast hadn't blocked it. We do something analogous for 'or'. With this patch we allow that transformation to happen directly in foldCastedBitwiseLogic. And we now support the same thing for 'xor'. This is definitely opening up many other cases, but since we already went around it for some cases hopefully it's ok. Differential Revision: https://reviews.llvm.org/D36213 git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@311508 91177308-0d34-0410-b5e6-96231b3b80d8
1 parent 1eae26a commit 1bc52fb

File tree

2 files changed

+2
-9
lines changed

2 files changed

+2
-9
lines changed

lib/Transforms/InstCombine/InstCombineAndOrXor.cpp

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -991,12 +991,6 @@ bool InstCombiner::shouldOptimizeCast(CastInst *CI) {
991991
if (isEliminableCastPair(PrecedingCI, CI))
992992
return false;
993993

994-
// If this is a vector sext from a compare, then we don't want to break the
995-
// idiom where each element of the extended vector is either zero or all ones.
996-
if (CI->getOpcode() == Instruction::SExt &&
997-
isa<CmpInst>(CastSrc) && CI->getDestTy()->isVectorTy())
998-
return false;
999-
1000994
return true;
1001995
}
1002996

test/Transforms/InstCombine/vector-casts.ll

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -96,10 +96,9 @@ define <2 x i64> @test6(<4 x float> %a, <4 x float> %b) {
9696
define <2 x i64> @test7(<4 x float> %a, <4 x float> %b) {
9797
; CHECK-LABEL: @test7(
9898
; CHECK-NEXT: [[CMP:%.*]] = fcmp ult <4 x float> [[A:%.*]], zeroinitializer
99-
; CHECK-NEXT: [[SEXT:%.*]] = sext <4 x i1> [[CMP]] to <4 x i32>
10099
; CHECK-NEXT: [[CMP4:%.*]] = fcmp ult <4 x float> [[B:%.*]], zeroinitializer
101-
; CHECK-NEXT: [[SEXT5:%.*]] = sext <4 x i1> [[CMP4]] to <4 x i32>
102-
; CHECK-NEXT: [[AND:%.*]] = xor <4 x i32> [[SEXT]], [[SEXT5]]
100+
; CHECK-NEXT: [[AND1:%.*]] = xor <4 x i1> [[CMP]], [[CMP4]]
101+
; CHECK-NEXT: [[AND:%.*]] = sext <4 x i1> [[AND1]] to <4 x i32>
103102
; CHECK-NEXT: [[CONV:%.*]] = bitcast <4 x i32> [[AND]] to <2 x i64>
104103
; CHECK-NEXT: ret <2 x i64> [[CONV]]
105104
;

0 commit comments

Comments
 (0)