1 ; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
2 ; RUN: opt -instcombine %s -S -o - | FileCheck %s
6 define i32 @neg_or_lshr_i32(i32 %x) {
7 ; CHECK-LABEL: @neg_or_lshr_i32(
8 ; CHECK-NEXT: [[TMP1:%.*]] = icmp ne i32 [[X:%.*]], 0
9 ; CHECK-NEXT: [[SHR:%.*]] = zext i1 [[TMP1]] to i32
10 ; CHECK-NEXT: ret i32 [[SHR]]
14 %shr = lshr i32 %or, 31
20 define i32 @neg_or_lshr_i32_commute(i32 %x0) {
21 ; CHECK-LABEL: @neg_or_lshr_i32_commute(
22 ; CHECK-NEXT: [[X:%.*]] = sdiv i32 42, [[X0:%.*]]
23 ; CHECK-NEXT: [[TMP1:%.*]] = icmp ne i32 [[X]], 0
24 ; CHECK-NEXT: [[SHR:%.*]] = zext i1 [[TMP1]] to i32
25 ; CHECK-NEXT: ret i32 [[SHR]]
27 %x = sdiv i32 42, %x0 ; thwart complexity-based canonicalization
30 %shr = lshr i32 %or, 31
36 define <4 x i32> @neg_or_lshr_i32_vec(<4 x i32> %x) {
37 ; CHECK-LABEL: @neg_or_lshr_i32_vec(
38 ; CHECK-NEXT: [[TMP1:%.*]] = icmp ne <4 x i32> [[X:%.*]], zeroinitializer
39 ; CHECK-NEXT: [[SHR:%.*]] = zext <4 x i1> [[TMP1]] to <4 x i32>
40 ; CHECK-NEXT: ret <4 x i32> [[SHR]]
42 %neg = sub <4 x i32> zeroinitializer, %x
43 %or = or <4 x i32> %neg, %x
44 %shr = lshr <4 x i32> %or, <i32 31, i32 31, i32 31, i32 31>
48 define <4 x i32> @neg_or_lshr_i32_vec_commute(<4 x i32> %x0) {
49 ; CHECK-LABEL: @neg_or_lshr_i32_vec_commute(
50 ; CHECK-NEXT: [[X:%.*]] = sdiv <4 x i32> <i32 42, i32 42, i32 42, i32 42>, [[X0:%.*]]
51 ; CHECK-NEXT: [[TMP1:%.*]] = icmp ne <4 x i32> [[X]], zeroinitializer
52 ; CHECK-NEXT: [[SHR:%.*]] = zext <4 x i1> [[TMP1]] to <4 x i32>
53 ; CHECK-NEXT: ret <4 x i32> [[SHR]]
55 %x = sdiv <4 x i32> <i32 42, i32 42, i32 42, i32 42>, %x0 ; thwart complexity-based canonicalization
56 %neg = sub <4 x i32> zeroinitializer, %x
57 %or = or <4 x i32> %x, %neg
58 %shr = lshr <4 x i32> %or, <i32 31, i32 31, i32 31, i32 31>
64 define i32 @neg_extra_use_or_lshr_i32(i32 %x, i32* %p) {
65 ; CHECK-LABEL: @neg_extra_use_or_lshr_i32(
66 ; CHECK-NEXT: [[NEG:%.*]] = sub i32 0, [[X:%.*]]
67 ; CHECK-NEXT: [[TMP1:%.*]] = icmp ne i32 [[X]], 0
68 ; CHECK-NEXT: [[SHR:%.*]] = zext i1 [[TMP1]] to i32
69 ; CHECK-NEXT: store i32 [[NEG]], i32* [[P:%.*]], align 4
70 ; CHECK-NEXT: ret i32 [[SHR]]
74 %shr = lshr i32 %or, 31
75 store i32 %neg, i32* %p
81 define i32 @neg_or_extra_use_lshr_i32(i32 %x, i32* %p) {
82 ; CHECK-LABEL: @neg_or_extra_use_lshr_i32(
83 ; CHECK-NEXT: [[NEG:%.*]] = sub i32 0, [[X:%.*]]
84 ; CHECK-NEXT: [[OR:%.*]] = or i32 [[NEG]], [[X]]
85 ; CHECK-NEXT: [[SHR:%.*]] = lshr i32 [[OR]], 31
86 ; CHECK-NEXT: store i32 [[OR]], i32* [[P:%.*]], align 4
87 ; CHECK-NEXT: ret i32 [[SHR]]
91 %shr = lshr i32 %or, 31
92 store i32 %or, i32* %p