summaryrefslogtreecommitdiffstats
path: root/llvm
diff options
context:
space:
mode:
authorSanjay Patel <spatel@rotateright.com>2016-10-27 21:19:40 +0000
committerSanjay Patel <spatel@rotateright.com>2016-10-27 21:19:40 +0000
commitc0de9c9e40b3eb5c2422d72ff5e0e3962baa714b (patch)
tree9ee466900f047ee93d5af668f0c46b65394aae16 /llvm
parentc1708b0d9959db2057ae7cfc0f95fb7ecb6adbca (diff)
downloadbcm5719-llvm-c0de9c9e40b3eb5c2422d72ff5e0e3962baa714b.tar.gz
bcm5719-llvm-c0de9c9e40b3eb5c2422d72ff5e0e3962baa714b.zip
[InstCombine] fix foldSPFofSPF() to handle vector splats
llvm-svn: 285345
Diffstat (limited to 'llvm')
-rw-r--r--llvm/lib/Transforms/InstCombine/InstCombineSelect.cpp40
-rw-r--r--llvm/test/Transforms/InstCombine/select.ll14
2 files changed, 24 insertions, 30 deletions
diff --git a/llvm/lib/Transforms/InstCombine/InstCombineSelect.cpp b/llvm/lib/Transforms/InstCombine/InstCombineSelect.cpp
index 7e9fb79f0de..165b54bcdee 100644
--- a/llvm/lib/Transforms/InstCombine/InstCombineSelect.cpp
+++ b/llvm/lib/Transforms/InstCombine/InstCombineSelect.cpp
@@ -678,28 +678,24 @@ Instruction *InstCombiner::foldSPFofSPF(Instruction *Inner,
}
if (SPF1 == SPF2) {
- if (ConstantInt *CB = dyn_cast<ConstantInt>(B)) {
- if (ConstantInt *CC = dyn_cast<ConstantInt>(C)) {
- const APInt &ACB = CB->getValue();
- const APInt &ACC = CC->getValue();
-
- // MIN(MIN(A, 23), 97) -> MIN(A, 23)
- // MAX(MAX(A, 97), 23) -> MAX(A, 97)
- if ((SPF1 == SPF_UMIN && ACB.ule(ACC)) ||
- (SPF1 == SPF_SMIN && ACB.sle(ACC)) ||
- (SPF1 == SPF_UMAX && ACB.uge(ACC)) ||
- (SPF1 == SPF_SMAX && ACB.sge(ACC)))
- return replaceInstUsesWith(Outer, Inner);
-
- // MIN(MIN(A, 97), 23) -> MIN(A, 23)
- // MAX(MAX(A, 23), 97) -> MAX(A, 97)
- if ((SPF1 == SPF_UMIN && ACB.ugt(ACC)) ||
- (SPF1 == SPF_SMIN && ACB.sgt(ACC)) ||
- (SPF1 == SPF_UMAX && ACB.ult(ACC)) ||
- (SPF1 == SPF_SMAX && ACB.slt(ACC))) {
- Outer.replaceUsesOfWith(Inner, A);
- return &Outer;
- }
+ const APInt *CB, *CC;
+ if (match(B, m_APInt(CB)) && match(C, m_APInt(CC))) {
+ // MIN(MIN(A, 23), 97) -> MIN(A, 23)
+ // MAX(MAX(A, 97), 23) -> MAX(A, 97)
+ if ((SPF1 == SPF_UMIN && CB->ule(*CC)) ||
+ (SPF1 == SPF_SMIN && CB->sle(*CC)) ||
+ (SPF1 == SPF_UMAX && CB->uge(*CC)) ||
+ (SPF1 == SPF_SMAX && CB->sge(*CC)))
+ return replaceInstUsesWith(Outer, Inner);
+
+ // MIN(MIN(A, 97), 23) -> MIN(A, 23)
+ // MAX(MAX(A, 23), 97) -> MAX(A, 97)
+ if ((SPF1 == SPF_UMIN && CB->ugt(*CC)) ||
+ (SPF1 == SPF_SMIN && CB->sgt(*CC)) ||
+ (SPF1 == SPF_UMAX && CB->ult(*CC)) ||
+ (SPF1 == SPF_SMAX && CB->slt(*CC))) {
+ Outer.replaceUsesOfWith(Inner, A);
+ return &Outer;
}
}
}
diff --git a/llvm/test/Transforms/InstCombine/select.ll b/llvm/test/Transforms/InstCombine/select.ll
index 3f811b69c1c..69b7b57e513 100644
--- a/llvm/test/Transforms/InstCombine/select.ll
+++ b/llvm/test/Transforms/InstCombine/select.ll
@@ -1300,14 +1300,11 @@ define i32 @test68(i32 %x) {
ret i32 %retval
}
-; FIXME - vector neglect
define <2 x i32> @test68vec(<2 x i32> %x) {
; CHECK-LABEL: @test68vec(
; CHECK-NEXT: [[CMP:%.*]] = icmp sgt <2 x i32> %x, <i32 11, i32 11>
; CHECK-NEXT: [[COND:%.*]] = select <2 x i1> [[CMP]], <2 x i32> <i32 11, i32 11>, <2 x i32> %x
-; CHECK-NEXT: [[CMP3:%.*]] = icmp sgt <2 x i32> [[COND]], <i32 92, i32 92>
-; CHECK-NEXT: [[RETVAL:%.*]] = select <2 x i1> [[CMP3]], <2 x i32> <i32 92, i32 92>, <2 x i32> [[COND]]
-; CHECK-NEXT: ret <2 x i32> [[RETVAL]]
+; CHECK-NEXT: ret <2 x i32> [[COND]]
;
%cmp = icmp slt <2 x i32> <i32 11, i32 11>, %x
%cond = select <2 x i1> %cmp, <2 x i32> <i32 11, i32 11>, <2 x i32> %x
@@ -1372,13 +1369,14 @@ define i32 @test72(i32 %x) {
ret i32 %retval
}
-; FIXME - vector neglect
+; FIXME - vector neglect: FoldOrOfICmps()
+
define <2 x i32> @test72vec(<2 x i32> %x) {
; CHECK-LABEL: @test72vec(
; CHECK-NEXT: [[CMP:%.*]] = icmp sgt <2 x i32> %x, <i32 92, i32 92>
-; CHECK-NEXT: [[COND:%.*]] = select <2 x i1> [[CMP]], <2 x i32> <i32 92, i32 92>, <2 x i32> %x
-; CHECK-NEXT: [[CMP3:%.*]] = icmp sgt <2 x i32> [[COND]], <i32 11, i32 11>
-; CHECK-NEXT: [[RETVAL:%.*]] = select <2 x i1> [[CMP3]], <2 x i32> <i32 11, i32 11>, <2 x i32> [[COND]]
+; CHECK-NEXT: [[CMP31:%.*]] = icmp sgt <2 x i32> %x, <i32 11, i32 11>
+; CHECK-NEXT: [[CMP3:%.*]] = or <2 x i1> [[CMP]], [[CMP31:%.*]]
+; CHECK-NEXT: [[RETVAL:%.*]] = select <2 x i1> [[CMP3]], <2 x i32> <i32 11, i32 11>, <2 x i32> %x
; CHECK-NEXT: ret <2 x i32> [[RETVAL]]
;
%cmp = icmp sgt <2 x i32> %x, <i32 92, i32 92>
OpenPOWER on IntegriCloud