+; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
; RUN: opt < %s -instcombine -S | FileCheck %s
define i32 @abs_abs_x01(i32 %x) {
; CHECK-NEXT: ret i32 [[SEL]]
}
+; FIXME - vectors should get the same folds
+define <2 x i32> @abs_abs_x01_vec(<2 x i32> %x) {
+; CHECK-LABEL: @abs_abs_x01_vec(
+; CHECK-NEXT: [[CMP:%.*]] = icmp sgt <2 x i32> %x, <i32 -1, i32 -1>
+; CHECK-NEXT: [[SUB:%.*]] = sub nsw <2 x i32> zeroinitializer, %x
+; CHECK-NEXT: [[COND:%.*]] = select <2 x i1> [[CMP]], <2 x i32> %x, <2 x i32> [[SUB]]
+; CHECK-NEXT: [[CMP1:%.*]] = icmp sgt <2 x i32> [[COND]], <i32 -1, i32 -1>
+; CHECK-NEXT: [[SUB16:%.*]] = sub nsw <2 x i32> zeroinitializer, [[COND]]
+; CHECK-NEXT: [[COND18:%.*]] = select <2 x i1> [[CMP1]], <2 x i32> [[COND]], <2 x i32> [[SUB16]]
+; CHECK-NEXT: ret <2 x i32> [[COND18]]
+;
+ %cmp = icmp sgt <2 x i32> %x, <i32 -1, i32 -1>
+ %sub = sub nsw <2 x i32> zeroinitializer, %x
+ %cond = select <2 x i1> %cmp, <2 x i32> %x, <2 x i32> %sub
+ %cmp1 = icmp sgt <2 x i32> %cond, <i32 -1, i32 -1>
+ %sub16 = sub nsw <2 x i32> zeroinitializer, %cond
+ %cond18 = select <2 x i1> %cmp1, <2 x i32> %cond, <2 x i32> %sub16
+ ret <2 x i32> %cond18
+}
+
define i32 @abs_abs_x02(i32 %x) {
%cmp = icmp sgt i32 %x, 0
%sub = sub nsw i32 0, %x
; CHECK-NEXT: ret i32 [[SEL]]
}
+; FIXME - vectors should get the same folds
+define <2 x i32> @abs_abs_x04_vec(<2 x i32> %x) {
+; CHECK-LABEL: @abs_abs_x04_vec(
+; CHECK-NEXT: [[CMP:%.*]] = icmp slt <2 x i32> %x, <i32 1, i32 1>
+; CHECK-NEXT: [[SUB:%.*]] = sub nsw <2 x i32> zeroinitializer, %x
+; CHECK-NEXT: [[COND:%.*]] = select <2 x i1> [[CMP]], <2 x i32> [[SUB]], <2 x i32> %x
+; CHECK-NEXT: [[CMP1:%.*]] = icmp sgt <2 x i32> [[COND]], <i32 -1, i32 -1>
+; CHECK-NEXT: [[SUB16:%.*]] = sub nsw <2 x i32> zeroinitializer, [[COND]]
+; CHECK-NEXT: [[COND18:%.*]] = select <2 x i1> [[CMP1]], <2 x i32> [[COND]], <2 x i32> [[SUB16]]
+; CHECK-NEXT: ret <2 x i32> [[COND18]]
+;
+ %cmp = icmp slt <2 x i32> %x, <i32 1, i32 1>
+ %sub = sub nsw <2 x i32> zeroinitializer, %x
+ %cond = select <2 x i1> %cmp, <2 x i32> %sub, <2 x i32> %x
+ %cmp1 = icmp sgt <2 x i32> %cond, <i32 -1, i32 -1>
+ %sub16 = sub nsw <2 x i32> zeroinitializer, %cond
+ %cond18 = select <2 x i1> %cmp1, <2 x i32> %cond, <2 x i32> %sub16
+ ret <2 x i32> %cond18
+}
+
define i32 @abs_abs_x05(i32 %x) {
%cmp = icmp sgt i32 %x, -1
%sub = sub nsw i32 0, %x
; CHECK-NEXT: [[NEG:%[a-z0-9]+]] = sub nsw i32 0, %x
; CHECK-NEXT: [[SEL:%[a-z0-9]+]] = select i1 [[CMP]], i32 %x, i32 [[NEG]]
; CHECK-NEXT: ret i32 [[SEL]]
-}
\ No newline at end of file
+}
ret i32 %smax96
}
+; FIXME - vectors should get the same folds
+define <2 x i32> @max_of_nots_vec(<2 x i32> %x, <2 x i32> %y) {
+; CHECK-LABEL: @max_of_nots_vec(
+; CHECK-NEXT: [[C0:%.*]] = icmp sgt <2 x i32> %y, zeroinitializer
+; CHECK-NEXT: [[XOR_Y:%.*]] = xor <2 x i32> %y, <i32 -1, i32 -1>
+; CHECK-NEXT: [[S0:%.*]] = select <2 x i1> [[C0]], <2 x i32> [[XOR_Y]], <2 x i32> <i32 -1, i32 -1>
+; CHECK-NEXT: [[XOR_X:%.*]] = xor <2 x i32> %x, <i32 -1, i32 -1>
+; CHECK-NEXT: [[C1:%.*]] = icmp slt <2 x i32> [[S0]], [[XOR_X]]
+; CHECK-NEXT: [[SMAX96:%.*]] = select <2 x i1> [[C1]], <2 x i32> [[XOR_X]], <2 x i32> [[S0]]
+; CHECK-NEXT: ret <2 x i32> [[SMAX96]]
+;
+ %c0 = icmp sgt <2 x i32> %y, zeroinitializer
+ %xor_y = xor <2 x i32> %y, <i32 -1, i32 -1>
+ %s0 = select <2 x i1> %c0, <2 x i32> %xor_y, <2 x i32> <i32 -1, i32 -1>
+ %xor_x = xor <2 x i32> %x, <i32 -1, i32 -1>
+ %c1 = icmp slt <2 x i32> %s0, %xor_x
+ %smax96 = select <2 x i1> %c1, <2 x i32> %xor_x, <2 x i32> %s0
+ ret <2 x i32> %smax96
+}
+
ret i32 %s1
}
-define i32 @test_max_of_min(i32 %a) {
; MAX(MIN(%a, -1), -1) == -1
+define i32 @test_max_of_min(i32 %a) {
; CHECK-LABEL: @test_max_of_min(
-; CHECK: ret i32 -1
+; CHECK-NEXT: ret i32 -1
+;
%not_a = xor i32 %a, -1
%c0 = icmp sgt i32 %a, 0
%s0 = select i1 %c0, i32 %not_a, i32 -1
ret i32 %s1
}
+; FIXME - vectors should get the same folds
+define <2 x i32> @test_max_of_min_vec(<2 x i32> %a) {
+; CHECK-LABEL: @test_max_of_min_vec(
+; CHECK-NEXT: [[NOT_A:%.*]] = xor <2 x i32> %a, <i32 -1, i32 -1>
+; CHECK-NEXT: [[C0:%.*]] = icmp sgt <2 x i32> %a, zeroinitializer
+; CHECK-NEXT: [[S0:%.*]] = select <2 x i1> [[C0]], <2 x i32> [[NOT_A]], <2 x i32> <i32 -1, i32 -1>
+; CHECK-NEXT: [[C1:%.*]] = icmp sgt <2 x i32> [[S0]], <i32 -1, i32 -1>
+; CHECK-NEXT: [[S1:%.*]] = select <2 x i1> [[C1]], <2 x i32> [[S0]], <2 x i32> <i32 -1, i32 -1>
+; CHECK-NEXT: ret <2 x i32> [[S1]]
+;
+ %not_a = xor <2 x i32> %a, <i32 -1, i32 -1>
+ %c0 = icmp sgt <2 x i32> %a, zeroinitializer
+ %s0 = select <2 x i1> %c0, <2 x i32> %not_a, <2 x i32> <i32 -1, i32 -1>
+ %c1 = icmp sgt <2 x i32> %s0, <i32 -1, i32 -1>
+ %s1 = select <2 x i1> %c1, <2 x i32> %s0, <2 x i32> <i32 -1, i32 -1>
+ ret <2 x i32> %s1
+}
define i32 @PR23757(i32 %x) {
; CHECK-LABEL: @PR23757
ret i32 %sel
}
-
define i32 @PR27137(i32 %a) {
; CHECK-LABEL: @PR27137(
; CHECK-NEXT: %not_a = xor i32 %a, -1
+; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
; RUN: opt < %s -instcombine -S | FileCheck %s
define i32 @foo(i32) local_unnamed_addr #0 {
; CHECK-NEXT: [[SEL:%[a-z0-9]+]] = select i1 [[CMP]], i32 %x, i32 [[NEG]], !prof ![[MD1]]
}
+; FIXME - vectors should get the same folds
+define <2 x i32> @abs_nabs_x01_vec(<2 x i32> %x) {
+; CHECK-LABEL: @abs_nabs_x01_vec(
+; CHECK-NEXT: [[CMP:%.*]] = icmp sgt <2 x i32> %x, <i32 -1, i32 -1>
+; CHECK-NEXT: [[SUB:%.*]] = sub nsw <2 x i32> zeroinitializer, %x
+; CHECK-NEXT: [[COND:%.*]] = select <2 x i1> [[CMP]], <2 x i32> [[SUB]], <2 x i32> %x, !prof !0
+; CHECK-NEXT: [[CMP1:%.*]] = icmp sgt <2 x i32> [[COND]], <i32 -1, i32 -1>
+; CHECK-NEXT: [[SUB16:%.*]] = sub nsw <2 x i32> zeroinitializer, [[COND]]
+; CHECK-NEXT: [[COND18:%.*]] = select <2 x i1> [[CMP1]], <2 x i32> [[COND]], <2 x i32> [[SUB16]], !prof !2
+; CHECK-NEXT: ret <2 x i32> [[COND18]]
+;
+ %cmp = icmp sgt <2 x i32> %x, <i32 -1, i32 -1>
+ %sub = sub nsw <2 x i32> zeroinitializer, %x
+ %cond = select <2 x i1> %cmp, <2 x i32> %sub, <2 x i32> %x, !prof !1
+ %cmp1 = icmp sgt <2 x i32> %cond, <i32 -1, i32 -1>
+ %sub16 = sub nsw <2 x i32> zeroinitializer, %cond
+ %cond18 = select <2 x i1> %cmp1, <2 x i32> %cond, <2 x i32> %sub16, !prof !2
+ ret <2 x i32> %cond18
+}
; SMAX(SMAX(x, y), x) -> SMAX(x, y)
define i32 @test30(i32 %x, i32 %y) {