summaryrefslogtreecommitdiffstats
path: root/llvm/test/Transforms/InstCombine/select_meta.ll
diff options
context:
space:
mode:
Diffstat (limited to 'llvm/test/Transforms/InstCombine/select_meta.ll')
-rw-r--r--llvm/test/Transforms/InstCombine/select_meta.ll140
1 files changed, 128 insertions, 12 deletions
diff --git a/llvm/test/Transforms/InstCombine/select_meta.ll b/llvm/test/Transforms/InstCombine/select_meta.ll
index 40c8a0cfc7b..27c0c1c309c 100644
--- a/llvm/test/Transforms/InstCombine/select_meta.ll
+++ b/llvm/test/Transforms/InstCombine/select_meta.ll
@@ -1,4 +1,6 @@
-; NOTE: Assertions have been autogenerated by utils/update_test_checks.py and enhanced to include metadata checking.
+; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
+; and enhanced to include metadata checking.
+
; RUN: opt < %s -instcombine -S | FileCheck %s
define i32 @foo(i32) local_unnamed_addr #0 {
@@ -51,12 +53,11 @@ define i32 @foo2(i32, i32) local_unnamed_addr #0 {
ret i32 %6
}
-; condition swapped
define i64 @test43(i32 %a) nounwind {
; CHECK-LABEL: @test43(
; CHECK-NEXT: [[A_EXT:%.*]] = sext i32 %a to i64
-; CHECK-NEXT: [[IS_A_NONNEGATIVE:%.*]] = icmp slt i64 [[A_EXT]], 0
-; CHECK-NEXT: [[MAX:%.*]] = select i1 [[IS_A_NONNEGATIVE]], i64 0, i64 [[A_EXT]], !prof ![[MD3:[0-9]+]]
+; CHECK-NEXT: [[TMP1:%.*]] = icmp sgt i64 [[A_EXT]], 0
+; CHECK-NEXT: [[MAX:%.*]] = select i1 [[TMP1]], i64 [[A_EXT]], i64 0, !prof ![[MD1]]
; CHECK-NEXT: ret i64 [[MAX]]
;
%a_ext = sext i32 %a to i64
@@ -136,10 +137,12 @@ define i32 @test30(i32 %x, i32 %y) {
ret i32 %retval
}
+; Swap predicate / metadata order
+; SMAX(SMAX(X, 75), 36) -> SMAX(X, 75)
define i32 @test70(i32 %x) {
; CHECK-LABEL: @test70(
-; CHECK-NEXT: [[CMP:%.*]] = icmp slt i32 %x, 75
-; CHECK-NEXT: [[COND:%.*]] = select i1 [[CMP]], i32 75, i32 %x, !prof ![[MD1]]
+; CHECK-NEXT: [[TMP1:%.*]] = icmp sgt i32 %x, 75
+; CHECK-NEXT: [[COND:%.*]] = select i1 [[TMP1]], i32 %x, i32 75, !prof ![[MD3:[0-9]+]]
; CHECK-NEXT: ret i32 [[COND]]
;
%cmp = icmp slt i32 %x, 75
@@ -149,12 +152,12 @@ define i32 @test70(i32 %x) {
ret i32 %retval
}
-
+; Swap predicate / metadata order
; SMIN(SMIN(X, 92), 11) -> SMIN(X, 11)
define i32 @test72(i32 %x) {
; CHECK-LABEL: @test72(
-; CHECK-NEXT: [[CMP31:%.*]] = icmp sgt i32 %x, 11
-; CHECK-NEXT: [[RETVAL:%.*]] = select i1 [[CMP31]], i32 11, i32 %x, !prof ![[MD2:[0-9]+]]
+; CHECK-NEXT: [[TMP1:%.*]] = icmp slt i32 %x, 11
+; CHECK-NEXT: [[RETVAL:%.*]] = select i1 [[TMP1]], i32 %x, i32 11, !prof ![[MD4:[0-9]+]]
; CHECK-NEXT: ret i32 [[RETVAL]]
;
%cmp = icmp sgt i32 %x, 92
@@ -164,11 +167,12 @@ define i32 @test72(i32 %x) {
ret i32 %retval
}
+; Swap predicate / metadata order
; SMAX(SMAX(X, 36), 75) -> SMAX(X, 75)
define i32 @test74(i32 %x) {
; CHECK-LABEL: @test74(
-; CHECK-NEXT: [[CMP31:%.*]] = icmp slt i32 %x, 75
-; CHECK-NEXT: [[RETVAL:%.*]] = select i1 [[CMP31]], i32 75, i32 %x, !prof ![[MD2]]
+; CHECK-NEXT: [[TMP1:%.*]] = icmp sgt i32 %x, 75
+; CHECK-NEXT: [[RETVAL:%.*]] = select i1 [[TMP1]], i32 %x, i32 75, !prof ![[MD4]]
; CHECK-NEXT: ret i32 [[RETVAL]]
;
%cmp = icmp slt i32 %x, 36
@@ -178,10 +182,122 @@ define i32 @test74(i32 %x) {
ret i32 %retval
}
+; FIXME:
+; The compare should change, but the metadata remains the same because the select operands are not swapped.
+define i32 @smin1(i32 %x) {
+; CHECK-LABEL: @smin1(
+; CHECK-NEXT: [[NOT_X:%.*]] = xor i32 %x, -1
+; CHECK-NEXT: [[CMP:%.*]] = icmp sgt i32 %x, 0
+; CHECK-NEXT: [[SEL:%.*]] = select i1 [[CMP]], i32 [[NOT_X]], i32 -1, !prof ![[MD1]]
+; CHECK-NEXT: ret i32 [[SEL]]
+;
+ %not_x = xor i32 %x, -1
+ %cmp = icmp sgt i32 %x, 0
+ %sel = select i1 %cmp, i32 %not_x, i32 -1, !prof !1
+ ret i32 %sel
+}
+
+; FIXME:
+; The compare should change, and the metadata is swapped because the select operands are swapped.
+define i32 @smin2(i32 %x) {
+; CHECK-LABEL: @smin2(
+; CHECK-NEXT: [[NOT_X:%.*]] = xor i32 %x, -1
+; CHECK-NEXT: [[CMP:%.*]] = icmp slt i32 %x, 0
+; CHECK-NEXT: [[SEL:%.*]] = select i1 [[CMP]], i32 -1, i32 [[NOT_X]], !prof ![[MD1]]
+; CHECK-NEXT: ret i32 [[SEL]]
+;
+ %not_x = xor i32 %x, -1
+ %cmp = icmp slt i32 %x, 0
+ %sel = select i1 %cmp, i32 -1, i32 %not_x, !prof !1
+ ret i32 %sel
+}
+
+; FIXME:
+; The compare should change, but the metadata remains the same because the select operands are not swapped.
+define i32 @smax1(i32 %x) {
+; CHECK-LABEL: @smax1(
+; CHECK-NEXT: [[NOT_X:%.*]] = xor i32 %x, -1
+; CHECK-NEXT: [[CMP:%.*]] = icmp slt i32 %x, 0
+; CHECK-NEXT: [[SEL:%.*]] = select i1 [[CMP]], i32 [[NOT_X]], i32 -1, !prof ![[MD1]]
+; CHECK-NEXT: ret i32 [[SEL]]
+;
+ %not_x = xor i32 %x, -1
+ %cmp = icmp slt i32 %x, 0
+ %sel = select i1 %cmp, i32 %not_x, i32 -1, !prof !1
+ ret i32 %sel
+}
+
+; FIXME:
+; The compare should change, and the metadata is swapped because the select operands are swapped.
+define i32 @smax2(i32 %x) {
+; CHECK-LABEL: @smax2(
+; CHECK-NEXT: [[NOT_X:%.*]] = xor i32 %x, -1
+; CHECK-NEXT: [[CMP:%.*]] = icmp sgt i32 %x, 0
+; CHECK-NEXT: [[SEL:%.*]] = select i1 [[CMP]], i32 -1, i32 [[NOT_X]], !prof ![[MD1]]
+; CHECK-NEXT: ret i32 [[SEL]]
+;
+ %not_x = xor i32 %x, -1
+ %cmp = icmp sgt i32 %x, 0
+ %sel = select i1 %cmp, i32 -1, i32 %not_x, !prof !1
+ ret i32 %sel
+}
+
+; FIXME:
+; The compare should change, but the metadata remains the same because the select operands are not swapped.
+define i32 @umin1(i32 %x) {
+; CHECK-LABEL: @umin1(
+; CHECK-NEXT: [[CMP:%.*]] = icmp sgt i32 %x, -1
+; CHECK-NEXT: [[SEL:%.*]] = select i1 [[CMP]], i32 %x, i32 -2147483648, !prof ![[MD1]]
+; CHECK-NEXT: ret i32 [[SEL]]
+;
+ %cmp = icmp sgt i32 %x, -1
+ %sel = select i1 %cmp, i32 %x, i32 -2147483648, !prof !1
+ ret i32 %sel
+}
+
+; FIXME:
+; The compare should change, and the metadata is swapped because the select operands are swapped.
+define i32 @umin2(i32 %x) {
+; CHECK-LABEL: @umin2(
+; CHECK-NEXT: [[CMP:%.*]] = icmp slt i32 %x, 0
+; CHECK-NEXT: [[SEL:%.*]] = select i1 [[CMP]], i32 2147483647, i32 %x, !prof ![[MD1]]
+; CHECK-NEXT: ret i32 [[SEL]]
+;
+ %cmp = icmp slt i32 %x, 0
+ %sel = select i1 %cmp, i32 2147483647, i32 %x, !prof !1
+ ret i32 %sel
+}
+
+; FIXME:
+; The compare should change, but the metadata remains the same because the select operands are not swapped.
+define i32 @umax1(i32 %x) {
+; CHECK-LABEL: @umax1(
+; CHECK-NEXT: [[CMP:%.*]] = icmp slt i32 %x, 0
+; CHECK-NEXT: [[SEL:%.*]] = select i1 [[CMP]], i32 %x, i32 2147483647, !prof ![[MD1]]
+; CHECK-NEXT: ret i32 [[SEL]]
+;
+ %cmp = icmp slt i32 %x, 0
+ %sel = select i1 %cmp, i32 %x, i32 2147483647, !prof !1
+ ret i32 %sel
+}
+
+; FIXME:
+; The compare should change, and the metadata is swapped because the select operands are swapped.
+define i32 @umax2(i32 %x) {
+; CHECK-LABEL: @umax2(
+; CHECK-NEXT: [[CMP:%.*]] = icmp sgt i32 %x, -1
+; CHECK-NEXT: [[SEL:%.*]] = select i1 [[CMP]], i32 -2147483648, i32 %x, !prof ![[MD1]]
+; CHECK-NEXT: ret i32 [[SEL]]
+;
+ %cmp = icmp sgt i32 %x, -1
+ %sel = select i1 %cmp, i32 -2147483648, i32 %x, !prof !1
+ ret i32 %sel
+}
+
!1 = !{!"branch_weights", i32 2, i32 10}
!2 = !{!"branch_weights", i32 3, i32 10}
; CHECK-DAG: ![[MD1]] = !{!"branch_weights", i32 2, i32 10}
-; CHECK-DAG: ![[MD2]] = !{!"branch_weights", i32 3, i32 10}
; CHECK-DAG: ![[MD3]] = !{!"branch_weights", i32 10, i32 2}
+; CHECK-DAG: ![[MD4]] = !{!"branch_weights", i32 10, i32 3}
OpenPOWER on IntegriCloud