2016-05-28 17:44:28 +02:00
|
|
|
; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
|
2010-02-05 20:53:02 +01:00
|
|
|
; RUN: opt < %s -instcombine -S | FileCheck %s
|
|
|
|
|
2008-10-28 23:38:57 +01:00
|
|
|
|
2016-05-28 17:44:28 +02:00
|
|
|
define i32 @foo(i32 %a, i32 %b, i32 %c, i32 %d) {
|
|
|
|
; CHECK-LABEL: @foo(
|
|
|
|
; CHECK-NEXT: [[E:%.*]] = icmp slt i32 %a, %b
|
|
|
|
; CHECK-NEXT: [[J:%.*]] = select i1 [[E]], i32 %c, i32 %d
|
|
|
|
; CHECK-NEXT: ret i32 [[J]]
|
|
|
|
;
|
2008-10-28 23:38:57 +01:00
|
|
|
%e = icmp slt i32 %a, %b
|
|
|
|
%f = sext i1 %e to i32
|
|
|
|
%g = and i32 %c, %f
|
|
|
|
%h = xor i32 %f, -1
|
|
|
|
%i = and i32 %d, %h
|
|
|
|
%j = or i32 %g, %i
|
|
|
|
ret i32 %j
|
|
|
|
}
|
2016-05-28 17:44:28 +02:00
|
|
|
|
|
|
|
define i32 @bar(i32 %a, i32 %b, i32 %c, i32 %d) {
|
|
|
|
; CHECK-LABEL: @bar(
|
|
|
|
; CHECK-NEXT: [[E:%.*]] = icmp slt i32 %a, %b
|
|
|
|
; CHECK-NEXT: [[J:%.*]] = select i1 [[E]], i32 %c, i32 %d
|
|
|
|
; CHECK-NEXT: ret i32 [[J]]
|
|
|
|
;
|
2008-10-28 23:38:57 +01:00
|
|
|
%e = icmp slt i32 %a, %b
|
|
|
|
%f = sext i1 %e to i32
|
|
|
|
%g = and i32 %c, %f
|
|
|
|
%h = xor i32 %f, -1
|
|
|
|
%i = and i32 %d, %h
|
|
|
|
%j = or i32 %i, %g
|
|
|
|
ret i32 %j
|
|
|
|
}
|
2010-02-05 20:53:02 +01:00
|
|
|
|
2016-05-28 17:44:28 +02:00
|
|
|
define i32 @goo(i32 %a, i32 %b, i32 %c, i32 %d) {
|
|
|
|
; CHECK-LABEL: @goo(
|
|
|
|
; CHECK-NEXT: [[T0:%.*]] = icmp slt i32 %a, %b
|
|
|
|
; CHECK-NEXT: [[T3:%.*]] = select i1 [[T0]], i32 %c, i32 %d
|
|
|
|
; CHECK-NEXT: ret i32 [[T3]]
|
|
|
|
;
|
|
|
|
%t0 = icmp slt i32 %a, %b
|
|
|
|
%iftmp.0.0 = select i1 %t0, i32 -1, i32 0
|
|
|
|
%t1 = and i32 %iftmp.0.0, %c
|
2008-10-30 21:40:10 +01:00
|
|
|
%not = xor i32 %iftmp.0.0, -1
|
2016-05-28 17:44:28 +02:00
|
|
|
%t2 = and i32 %not, %d
|
|
|
|
%t3 = or i32 %t1, %t2
|
|
|
|
ret i32 %t3
|
2008-10-30 21:40:10 +01:00
|
|
|
}
|
2016-05-28 17:44:28 +02:00
|
|
|
|
|
|
|
define i32 @poo(i32 %a, i32 %b, i32 %c, i32 %d) {
|
|
|
|
; CHECK-LABEL: @poo(
|
|
|
|
; CHECK-NEXT: [[T0:%.*]] = icmp slt i32 %a, %b
|
|
|
|
; CHECK-NEXT: [[T3:%.*]] = select i1 [[T0]], i32 %c, i32 %d
|
|
|
|
; CHECK-NEXT: ret i32 [[T3]]
|
|
|
|
;
|
|
|
|
%t0 = icmp slt i32 %a, %b
|
|
|
|
%iftmp.0.0 = select i1 %t0, i32 -1, i32 0
|
|
|
|
%t1 = and i32 %iftmp.0.0, %c
|
|
|
|
%iftmp = select i1 %t0, i32 0, i32 -1
|
|
|
|
%t2 = and i32 %iftmp, %d
|
|
|
|
%t3 = or i32 %t1, %t2
|
|
|
|
ret i32 %t3
|
2008-11-16 05:25:26 +01:00
|
|
|
}
|
|
|
|
|
2016-05-28 17:44:28 +02:00
|
|
|
define i32 @par(i32 %a, i32 %b, i32 %c, i32 %d) {
|
|
|
|
; CHECK-LABEL: @par(
|
|
|
|
; CHECK-NEXT: [[T0:%.*]] = icmp slt i32 %a, %b
|
|
|
|
; CHECK-NEXT: [[T3:%.*]] = select i1 [[T0]], i32 %c, i32 %d
|
|
|
|
; CHECK-NEXT: ret i32 [[T3]]
|
|
|
|
;
|
|
|
|
%t0 = icmp slt i32 %a, %b
|
|
|
|
%iftmp.1.0 = select i1 %t0, i32 -1, i32 0
|
|
|
|
%t1 = and i32 %iftmp.1.0, %c
|
2008-10-30 21:40:10 +01:00
|
|
|
%not = xor i32 %iftmp.1.0, -1
|
2016-05-28 17:44:28 +02:00
|
|
|
%t2 = and i32 %not, %d
|
|
|
|
%t3 = or i32 %t1, %t2
|
|
|
|
ret i32 %t3
|
2008-10-30 21:40:10 +01:00
|
|
|
}
|
2016-05-28 18:10:37 +02:00
|
|
|
|
|
|
|
; FIXME: In the following tests, verify that a bitcast doesn't get in the way
|
2016-06-03 00:45:49 +02:00
|
|
|
; of a select transform. These bitcasts are common in SSE/AVX and possibly
|
|
|
|
; other vector code because of canonicalization to i64 elements for vectors.
|
2016-05-28 18:10:37 +02:00
|
|
|
|
2016-06-03 00:45:49 +02:00
|
|
|
define <2 x i64> @bitcast_select(<4 x i1> %cmp, <2 x i64> %a, <2 x i64> %b) {
|
|
|
|
; CHECK-LABEL: @bitcast_select(
|
2016-05-28 18:10:37 +02:00
|
|
|
; CHECK-NEXT: [[SEXT:%.*]] = sext <4 x i1> %cmp to <4 x i32>
|
2016-06-03 00:45:49 +02:00
|
|
|
; CHECK-NEXT: [[T2:%.*]] = bitcast <4 x i32> [[SEXT]] to <2 x i64>
|
|
|
|
; CHECK-NEXT: [[AND:%.*]] = and <2 x i64> [[T2]], %a
|
|
|
|
; CHECK-NEXT: [[NEG:%.*]] = xor <4 x i32> [[SEXT]], <i32 -1, i32 -1, i32 -1, i32 -1>
|
|
|
|
; CHECK-NEXT: [[NEG2:%.*]] = bitcast <4 x i32> [[NEG]] to <2 x i64>
|
|
|
|
; CHECK-NEXT: [[AND2:%.*]] = and <2 x i64> [[NEG2]], %b
|
|
|
|
; CHECK-NEXT: [[OR:%.*]] = or <2 x i64> [[AND]], [[AND2]]
|
|
|
|
; CHECK-NEXT: ret <2 x i64> [[OR]]
|
2016-05-28 18:10:37 +02:00
|
|
|
;
|
|
|
|
%sext = sext <4 x i1> %cmp to <4 x i32>
|
2016-06-03 00:45:49 +02:00
|
|
|
%t2 = bitcast <4 x i32> %sext to <2 x i64>
|
|
|
|
%and = and <2 x i64> %t2, %a
|
|
|
|
%neg = xor <4 x i32> %sext, <i32 -1, i32 -1, i32 -1, i32 -1>
|
|
|
|
%neg2 = bitcast <4 x i32> %neg to <2 x i64>
|
|
|
|
%and2 = and <2 x i64> %neg2, %b
|
|
|
|
%or = or <2 x i64> %and, %and2
|
|
|
|
ret <2 x i64> %or
|
2016-05-28 18:10:37 +02:00
|
|
|
}
|
|
|
|
|
2016-06-03 00:45:49 +02:00
|
|
|
define <2 x i64> @bitcast_select_swap_or_ops(<4 x i1> %cmp, <2 x i64> %a, <2 x i64> %b) {
|
|
|
|
; CHECK-LABEL: @bitcast_select_swap_or_ops(
|
2016-05-28 18:10:37 +02:00
|
|
|
; CHECK-NEXT: [[SEXT:%.*]] = sext <4 x i1> %cmp to <4 x i32>
|
2016-06-03 00:45:49 +02:00
|
|
|
; CHECK-NEXT: [[T2:%.*]] = bitcast <4 x i32> [[SEXT]] to <2 x i64>
|
|
|
|
; CHECK-NEXT: [[AND:%.*]] = and <2 x i64> [[T2]], %a
|
2016-05-28 18:10:37 +02:00
|
|
|
; CHECK-NEXT: [[NEG:%.*]] = xor <4 x i32> [[SEXT]], <i32 -1, i32 -1, i32 -1, i32 -1>
|
2016-06-03 00:45:49 +02:00
|
|
|
; CHECK-NEXT: [[NEG2:%.*]] = bitcast <4 x i32> [[NEG]] to <2 x i64>
|
|
|
|
; CHECK-NEXT: [[AND2:%.*]] = and <2 x i64> [[NEG2]], %b
|
|
|
|
; CHECK-NEXT: [[OR:%.*]] = or <2 x i64> [[AND2]], [[AND]]
|
|
|
|
; CHECK-NEXT: ret <2 x i64> [[OR]]
|
2016-05-28 18:10:37 +02:00
|
|
|
;
|
|
|
|
%sext = sext <4 x i1> %cmp to <4 x i32>
|
2016-06-03 00:45:49 +02:00
|
|
|
%t2 = bitcast <4 x i32> %sext to <2 x i64>
|
|
|
|
%and = and <2 x i64> %t2, %a
|
2016-05-28 18:10:37 +02:00
|
|
|
%neg = xor <4 x i32> %sext, <i32 -1, i32 -1, i32 -1, i32 -1>
|
2016-06-03 00:45:49 +02:00
|
|
|
%neg2 = bitcast <4 x i32> %neg to <2 x i64>
|
|
|
|
%and2 = and <2 x i64> %neg2, %b
|
|
|
|
%or = or <2 x i64> %and2, %and
|
|
|
|
ret <2 x i64> %or
|
2016-05-28 18:10:37 +02:00
|
|
|
}
|
|
|
|
|
2016-06-03 00:45:49 +02:00
|
|
|
define <2 x i64> @bitcast_select_swap_and_ops(<4 x i1> %cmp, <2 x i64> %a, <2 x i64> %b) {
|
|
|
|
; CHECK-LABEL: @bitcast_select_swap_and_ops(
|
2016-05-28 18:10:37 +02:00
|
|
|
; CHECK-NEXT: [[SEXT:%.*]] = sext <4 x i1> %cmp to <4 x i32>
|
2016-06-03 00:45:49 +02:00
|
|
|
; CHECK-NEXT: [[T2:%.*]] = bitcast <4 x i32> [[SEXT]] to <2 x i64>
|
|
|
|
; CHECK-NEXT: [[AND:%.*]] = and <2 x i64> [[T2]], %a
|
2016-05-28 18:10:37 +02:00
|
|
|
; CHECK-NEXT: [[NEG:%.*]] = xor <4 x i32> [[SEXT]], <i32 -1, i32 -1, i32 -1, i32 -1>
|
2016-06-03 00:45:49 +02:00
|
|
|
; CHECK-NEXT: [[NEG2:%.*]] = bitcast <4 x i32> [[NEG]] to <2 x i64>
|
|
|
|
; CHECK-NEXT: [[AND2:%.*]] = and <2 x i64> [[NEG2]], %b
|
|
|
|
; CHECK-NEXT: [[OR:%.*]] = or <2 x i64> [[AND]], [[AND2]]
|
|
|
|
; CHECK-NEXT: ret <2 x i64> [[OR]]
|
2016-05-28 18:10:37 +02:00
|
|
|
;
|
|
|
|
%sext = sext <4 x i1> %cmp to <4 x i32>
|
2016-06-03 00:45:49 +02:00
|
|
|
%t2 = bitcast <4 x i32> %sext to <2 x i64>
|
|
|
|
%and = and <2 x i64> %t2, %a
|
2016-05-28 18:10:37 +02:00
|
|
|
%neg = xor <4 x i32> %sext, <i32 -1, i32 -1, i32 -1, i32 -1>
|
2016-06-03 00:45:49 +02:00
|
|
|
%neg2 = bitcast <4 x i32> %neg to <2 x i64>
|
|
|
|
%and2 = and <2 x i64> %b, %neg2
|
|
|
|
%or = or <2 x i64> %and, %and2
|
|
|
|
ret <2 x i64> %or
|
2016-05-28 18:10:37 +02:00
|
|
|
}
|
|
|
|
|
2016-06-03 00:45:49 +02:00
|
|
|
define <2 x i64> @bitcast_select_swap_and_ops2(<4 x i1> %cmp, <2 x i64> %a, <2 x i64> %b) {
|
|
|
|
; CHECK-LABEL: @bitcast_select_swap_and_ops2(
|
2016-05-28 18:10:37 +02:00
|
|
|
; CHECK-NEXT: [[SEXT:%.*]] = sext <4 x i1> %cmp to <4 x i32>
|
2016-06-03 00:45:49 +02:00
|
|
|
; CHECK-NEXT: [[T2:%.*]] = bitcast <4 x i32> [[SEXT]] to <2 x i64>
|
|
|
|
; CHECK-NEXT: [[AND:%.*]] = and <2 x i64> [[T2]], %a
|
|
|
|
; CHECK-NEXT: [[NEG:%.*]] = xor <4 x i32> [[SEXT]], <i32 -1, i32 -1, i32 -1, i32 -1>
|
|
|
|
; CHECK-NEXT: [[NEG2:%.*]] = bitcast <4 x i32> [[NEG]] to <2 x i64>
|
|
|
|
; CHECK-NEXT: [[AND2:%.*]] = and <2 x i64> [[NEG2]], %b
|
|
|
|
; CHECK-NEXT: [[OR:%.*]] = or <2 x i64> [[AND]], [[AND2]]
|
|
|
|
; CHECK-NEXT: ret <2 x i64> [[OR]]
|
2016-05-28 18:10:37 +02:00
|
|
|
;
|
|
|
|
%sext = sext <4 x i1> %cmp to <4 x i32>
|
2016-06-03 00:45:49 +02:00
|
|
|
%t2 = bitcast <4 x i32> %sext to <2 x i64>
|
|
|
|
%and = and <2 x i64> %a, %t2
|
|
|
|
%neg = xor <4 x i32> %sext, <i32 -1, i32 -1, i32 -1, i32 -1>
|
|
|
|
%neg2 = bitcast <4 x i32> %neg to <2 x i64>
|
|
|
|
%and2 = and <2 x i64> %neg2, %b
|
|
|
|
%or = or <2 x i64> %and, %and2
|
|
|
|
ret <2 x i64> %or
|
2016-05-28 18:10:37 +02:00
|
|
|
}
|
|
|
|
|