1 ; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
2 ; RUN: opt -S -instcombine < %s | FileCheck %s
4 define i64 @sel_false_val_is_a_masked_shl_of_true_val1(i32 %x, i64 %y) {
5 ; CHECK-LABEL: @sel_false_val_is_a_masked_shl_of_true_val1(
6 ; CHECK-NEXT: [[TMP1:%.*]] = and i32 [[X:%.*]], 15
7 ; CHECK-NEXT: [[TMP2:%.*]] = shl nuw nsw i32 [[TMP1]], 2
8 ; CHECK-NEXT: [[TMP3:%.*]] = icmp eq i32 [[TMP1]], 0
9 ; CHECK-NEXT: [[NARROW:%.*]] = select i1 [[TMP3]], i32 0, i32 [[TMP2]]
10 ; CHECK-NEXT: [[TMP4:%.*]] = zext i32 [[NARROW]] to i64
11 ; CHECK-NEXT: [[TMP5:%.*]] = ashr i64 [[Y:%.*]], [[TMP4]]
12 ; CHECK-NEXT: ret i64 [[TMP5]]
15 %2 = shl nuw nsw i32 %1, 2
16 %3 = zext i32 %2 to i64
17 %4 = icmp eq i32 %1, 0
19 %6 = select i1 %4, i64 %y, i64 %5
23 define i64 @sel_false_val_is_a_masked_shl_of_true_val2(i32 %x, i64 %y) {
24 ; CHECK-LABEL: @sel_false_val_is_a_masked_shl_of_true_val2(
25 ; CHECK-NEXT: [[TMP1:%.*]] = shl i32 [[X:%.*]], 2
26 ; CHECK-NEXT: [[TMP2:%.*]] = and i32 [[TMP1]], 60
27 ; CHECK-NEXT: [[TMP3:%.*]] = zext i32 [[TMP2]] to i64
28 ; CHECK-NEXT: [[TMP4:%.*]] = ashr i64 [[Y:%.*]], [[TMP3]]
29 ; CHECK-NEXT: ret i64 [[TMP4]]
32 %2 = shl nuw nsw i32 %1, 2
33 %3 = zext i32 %2 to i64
34 %4 = icmp eq i32 %2, 0
36 %6 = select i1 %4, i64 %y, i64 %5
40 define i64 @sel_false_val_is_a_masked_lshr_of_true_val1(i32 %x, i64 %y) {
41 ; CHECK-LABEL: @sel_false_val_is_a_masked_lshr_of_true_val1(
42 ; CHECK-NEXT: [[TMP1:%.*]] = and i32 [[X:%.*]], 60
43 ; CHECK-NEXT: [[TMP2:%.*]] = lshr exact i32 [[TMP1]], 2
44 ; CHECK-NEXT: [[TMP3:%.*]] = icmp eq i32 [[TMP1]], 0
45 ; CHECK-NEXT: [[NARROW:%.*]] = select i1 [[TMP3]], i32 0, i32 [[TMP2]]
46 ; CHECK-NEXT: [[TMP4:%.*]] = zext i32 [[NARROW]] to i64
47 ; CHECK-NEXT: [[TMP5:%.*]] = ashr i64 [[Y:%.*]], [[TMP4]]
48 ; CHECK-NEXT: ret i64 [[TMP5]]
52 %3 = zext i32 %2 to i64
53 %4 = icmp eq i32 %1, 0
55 %6 = select i1 %4, i64 %y, i64 %5
59 define i64 @sel_false_val_is_a_masked_lshr_of_true_val2(i32 %x, i64 %y) {
60 ; CHECK-LABEL: @sel_false_val_is_a_masked_lshr_of_true_val2(
61 ; CHECK-NEXT: [[TMP1:%.*]] = lshr i32 [[X:%.*]], 2
62 ; CHECK-NEXT: [[TMP2:%.*]] = and i32 [[TMP1]], 15
63 ; CHECK-NEXT: [[TMP3:%.*]] = zext i32 [[TMP2]] to i64
64 ; CHECK-NEXT: [[TMP4:%.*]] = ashr i64 [[Y:%.*]], [[TMP3]]
65 ; CHECK-NEXT: ret i64 [[TMP4]]
69 %3 = zext i32 %2 to i64
70 %4 = icmp eq i32 %2, 0
72 %6 = select i1 %4, i64 %y, i64 %5
76 define i64 @sel_false_val_is_a_masked_ashr_of_true_val1(i32 %x, i64 %y) {
77 ; CHECK-LABEL: @sel_false_val_is_a_masked_ashr_of_true_val1(
78 ; CHECK-NEXT: [[TMP1:%.*]] = and i32 [[X:%.*]], -2147483588
79 ; CHECK-NEXT: [[TMP2:%.*]] = ashr exact i32 [[TMP1]], 2
80 ; CHECK-NEXT: [[TMP3:%.*]] = icmp eq i32 [[TMP1]], 0
81 ; CHECK-NEXT: [[NARROW:%.*]] = select i1 [[TMP3]], i32 0, i32 [[TMP2]]
82 ; CHECK-NEXT: [[TMP4:%.*]] = zext i32 [[NARROW]] to i64
83 ; CHECK-NEXT: [[TMP5:%.*]] = ashr i64 [[Y:%.*]], [[TMP4]]
84 ; CHECK-NEXT: ret i64 [[TMP5]]
86 %1 = and i32 %x, -2147483588
88 %3 = zext i32 %2 to i64
89 %4 = icmp eq i32 %1, 0
91 %6 = select i1 %4, i64 %y, i64 %5
95 define i64 @sel_false_val_is_a_masked_ashr_of_true_val2(i32 %x, i64 %y) {
96 ; CHECK-LABEL: @sel_false_val_is_a_masked_ashr_of_true_val2(
97 ; CHECK-NEXT: [[TMP1:%.*]] = ashr i32 [[X:%.*]], 2
98 ; CHECK-NEXT: [[TMP2:%.*]] = and i32 [[TMP1]], -536870897
99 ; CHECK-NEXT: [[TMP3:%.*]] = zext i32 [[TMP2]] to i64
100 ; CHECK-NEXT: [[TMP4:%.*]] = ashr i64 [[Y:%.*]], [[TMP3]]
101 ; CHECK-NEXT: ret i64 [[TMP4]]
103 %1 = and i32 %x, -2147483588
105 %3 = zext i32 %2 to i64
106 %4 = icmp eq i32 %2, 0
108 %6 = select i1 %4, i64 %y, i64 %5