1 ; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
2 ; RUN: opt < %s -instcombine -S | FileCheck %s
4 define i32 @sub1(i32 %x) {
6 ; CHECK-NEXT: [[Y:%.*]] = sub i32 0, [[X:%.*]]
7 ; CHECK-NEXT: [[Z:%.*]] = sdiv i32 [[Y]], 337
8 ; CHECK-NEXT: ret i32 [[Z]]
15 define i32 @sub2(i32 %x) {
17 ; CHECK-NEXT: [[Z:%.*]] = sdiv i32 [[X:%.*]], -337
18 ; CHECK-NEXT: ret i32 [[Z]]
20 %y = sub nsw i32 0, %x
25 define i1 @shl_icmp(i64 %X) {
26 ; CHECK-LABEL: @shl_icmp(
27 ; CHECK-NEXT: [[B:%.*]] = icmp eq i64 [[X:%.*]], 0
28 ; CHECK-NEXT: ret i1 [[B]]
30 %A = shl nuw i64 %X, 2 ; X/4
31 %B = icmp eq i64 %A, 0
35 define i64 @shl1(i64 %X, i64* %P) {
37 ; CHECK-NEXT: [[A:%.*]] = and i64 [[X:%.*]], 312
38 ; CHECK-NEXT: store i64 [[A]], i64* [[P:%.*]], align 4
39 ; CHECK-NEXT: [[B:%.*]] = shl nuw nsw i64 [[A]], 8
40 ; CHECK-NEXT: ret i64 [[B]]
43 store i64 %A, i64* %P ; multiple uses of A.
48 define i32 @preserve1(i32 %x) {
49 ; CHECK-LABEL: @preserve1(
50 ; CHECK-NEXT: [[ADD3:%.*]] = add nsw i32 [[X:%.*]], 5
51 ; CHECK-NEXT: ret i32 [[ADD3]]
53 %add = add nsw i32 %x, 2
54 %add3 = add nsw i32 %add, 3
58 define i8 @nopreserve1(i8 %x) {
59 ; CHECK-LABEL: @nopreserve1(
60 ; CHECK-NEXT: [[ADD3:%.*]] = add i8 [[X:%.*]], -126
61 ; CHECK-NEXT: ret i8 [[ADD3]]
63 %add = add nsw i8 %x, 127
64 %add3 = add nsw i8 %add, 3
68 define i8 @nopreserve2(i8 %x) {
69 ; CHECK-LABEL: @nopreserve2(
70 ; CHECK-NEXT: [[ADD3:%.*]] = add i8 [[X:%.*]], 3
71 ; CHECK-NEXT: ret i8 [[ADD3]]
74 %add3 = add nsw i8 %add, 2
78 define i8 @nopreserve3(i8 %A, i8 %B) {
79 ; CHECK-LABEL: @nopreserve3(
80 ; CHECK-NEXT: [[Y:%.*]] = add i8 [[A:%.*]], [[B:%.*]]
81 ; CHECK-NEXT: [[ADD:%.*]] = add i8 [[Y]], 20
82 ; CHECK-NEXT: ret i8 [[ADD]]
86 %add = add nsw i8 %x, %y
90 define i8 @nopreserve4(i8 %A, i8 %B) {
91 ; CHECK-LABEL: @nopreserve4(
92 ; CHECK-NEXT: [[Y:%.*]] = add i8 [[A:%.*]], [[B:%.*]]
93 ; CHECK-NEXT: [[ADD:%.*]] = add i8 [[Y]], 20
94 ; CHECK-NEXT: ret i8 [[ADD]]
96 %x = add nsw i8 %A, 10
97 %y = add nsw i8 %B, 10
98 %add = add nsw i8 %x, %y
102 ; TODO: computeKnownBits() should look through a shufflevector.
104 define <3 x i32> @shl_nuw_nsw_shuffle_splat_vec(<2 x i8> %x) {
105 ; CHECK-LABEL: @shl_nuw_nsw_shuffle_splat_vec(
106 ; CHECK-NEXT: [[T2:%.*]] = zext <2 x i8> [[X:%.*]] to <2 x i32>
107 ; CHECK-NEXT: [[SHUF:%.*]] = shufflevector <2 x i32> [[T2]], <2 x i32> undef, <3 x i32> <i32 1, i32 0, i32 1>
108 ; CHECK-NEXT: [[T3:%.*]] = shl nsw <3 x i32> [[SHUF]], <i32 17, i32 17, i32 17>
109 ; CHECK-NEXT: ret <3 x i32> [[T3]]
111 %t2 = zext <2 x i8> %x to <2 x i32>
112 %shuf = shufflevector <2 x i32> %t2, <2 x i32> undef, <3 x i32> <i32 1, i32 0, i32 1>
113 %t3 = shl <3 x i32> %shuf, <i32 17, i32 17, i32 17>
117 ; Negative test - if the shuffle mask contains an undef, we bail out to
118 ; avoid propagating information that may not be used consistently by callers.
120 define <3 x i32> @shl_nuw_nsw_shuffle_undef_elt_splat_vec(<2 x i8> %x) {
121 ; CHECK-LABEL: @shl_nuw_nsw_shuffle_undef_elt_splat_vec(
122 ; CHECK-NEXT: [[T2:%.*]] = zext <2 x i8> [[X:%.*]] to <2 x i32>
123 ; CHECK-NEXT: [[SHUF:%.*]] = shufflevector <2 x i32> [[T2]], <2 x i32> undef, <3 x i32> <i32 1, i32 undef, i32 0>
124 ; CHECK-NEXT: [[T3:%.*]] = shl <3 x i32> [[SHUF]], <i32 17, i32 17, i32 17>
125 ; CHECK-NEXT: ret <3 x i32> [[T3]]
127 %t2 = zext <2 x i8> %x to <2 x i32>
128 %shuf = shufflevector <2 x i32> %t2, <2 x i32> undef, <3 x i32> <i32 1, i32 undef, i32 0>
129 %t3 = shl <3 x i32> %shuf, <i32 17, i32 17, i32 17>