1 ; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
2 ; RUN: opt < %s -instcombine -S | FileCheck %s
4 ; No selects should remain.
6 define i41 @zext(i1 %C) {
8 ; CHECK-NEXT: [[V:%.*]] = zext i1 %C to i41
9 ; CHECK-NEXT: ret i41 [[V]]
11 %V = select i1 %C, i41 1, i41 0
15 define i41 @sext(i1 %C) {
17 ; CHECK-NEXT: [[V:%.*]] = sext i1 %C to i41
18 ; CHECK-NEXT: ret i41 [[V]]
20 %V = select i1 %C, i41 -1, i41 0
24 define i999 @not_zext(i1 %C) {
25 ; CHECK-LABEL: @not_zext(
26 ; CHECK-NEXT: [[NOT_C:%.*]] = xor i1 %C, true
27 ; CHECK-NEXT: [[V:%.*]] = zext i1 [[NOT_C]] to i999
28 ; CHECK-NEXT: ret i999 [[V]]
30 %V = select i1 %C, i999 0, i999 1
34 define i999 @not_sext(i1 %C) {
35 ; CHECK-LABEL: @not_sext(
36 ; CHECK-NEXT: [[NOT_C:%.*]] = xor i1 %C, true
37 ; CHECK-NEXT: [[V:%.*]] = sext i1 [[NOT_C]] to i999
38 ; CHECK-NEXT: ret i999 [[V]]
40 %V = select i1 %C, i999 0, i999 -1
44 ; Vector selects of vector splat constants match APInt too.
46 define <2 x i41> @zext_vec(<2 x i1> %C) {
47 ; CHECK-LABEL: @zext_vec(
48 ; CHECK-NEXT: [[V:%.*]] = zext <2 x i1> %C to <2 x i41>
49 ; CHECK-NEXT: ret <2 x i41> [[V]]
51 %V = select <2 x i1> %C, <2 x i41> <i41 1, i41 1>, <2 x i41> <i41 0, i41 0>
55 define <2 x i32> @sext_vec(<2 x i1> %C) {
56 ; CHECK-LABEL: @sext_vec(
57 ; CHECK-NEXT: [[V:%.*]] = sext <2 x i1> %C to <2 x i32>
58 ; CHECK-NEXT: ret <2 x i32> [[V]]
60 %V = select <2 x i1> %C, <2 x i32> <i32 -1, i32 -1>, <2 x i32> <i32 0, i32 0>
64 define <2 x i999> @not_zext_vec(<2 x i1> %C) {
65 ; CHECK-LABEL: @not_zext_vec(
66 ; CHECK-NEXT: [[NOT_C:%.*]] = xor <2 x i1> %C, <i1 true, i1 true>
67 ; CHECK-NEXT: [[V:%.*]] = zext <2 x i1> [[NOT_C]] to <2 x i999>
68 ; CHECK-NEXT: ret <2 x i999> [[V]]
70 %V = select <2 x i1> %C, <2 x i999> <i999 0, i999 0>, <2 x i999> <i999 1, i999 1>
74 define <2 x i64> @not_sext_vec(<2 x i1> %C) {
75 ; CHECK-LABEL: @not_sext_vec(
76 ; CHECK-NEXT: [[NOT_C:%.*]] = xor <2 x i1> %C, <i1 true, i1 true>
77 ; CHECK-NEXT: [[V:%.*]] = sext <2 x i1> [[NOT_C]] to <2 x i64>
78 ; CHECK-NEXT: ret <2 x i64> [[V]]
80 %V = select <2 x i1> %C, <2 x i64> <i64 0, i64 0>, <2 x i64> <i64 -1, i64 -1>
84 ; But don't touch this - we would need 3 instructions to extend and splat the scalar select condition.
86 define <2 x i32> @scalar_select_of_vectors(i1 %c) {
87 ; CHECK-LABEL: @scalar_select_of_vectors(
88 ; CHECK-NEXT: [[V:%.*]] = select i1 %c, <2 x i32> <i32 1, i32 1>, <2 x i32> zeroinitializer
89 ; CHECK-NEXT: ret <2 x i32> [[V]]
91 %V = select i1 %c, <2 x i32> <i32 1, i32 1>, <2 x i32> zeroinitializer
95 ;; (x <s 0) ? -1 : 0 -> ashr x, 31
97 define i41 @test3(i41 %X) {
98 ; CHECK-LABEL: @test3(
99 ; CHECK-NEXT: [[X_LOBIT:%.*]] = ashr i41 %X, 40
100 ; CHECK-NEXT: ret i41 [[X_LOBIT]]
102 %t = icmp slt i41 %X, 0
103 %V = select i1 %t, i41 -1, i41 0
107 ;; (x <s 0) ? -1 : 0 -> ashr x, 31
109 define i1023 @test4(i1023 %X) {
110 ; CHECK-LABEL: @test4(
111 ; CHECK-NEXT: [[X_LOBIT:%.*]] = ashr i1023 %X, 1022
112 ; CHECK-NEXT: ret i1023 [[X_LOBIT]]
114 %t = icmp slt i1023 %X, 0
115 %V = select i1 %t, i1023 -1, i1023 0