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:%.*]] = shl i32 [[X:%.*]], 2
7 ; CHECK-NEXT: [[TMP2:%.*]] = and i32 [[TMP1]], 60
8 ; CHECK-NEXT: [[TMP3:%.*]] = zext i32 [[TMP2]] to i64
9 ; CHECK-NEXT: [[TMP4:%.*]] = ashr i64 [[Y:%.*]], [[TMP3]]
10 ; CHECK-NEXT: ret i64 [[TMP4]]
13 %2 = shl nuw nsw i32 %1, 2
14 %3 = zext i32 %2 to i64
15 %4 = icmp eq i32 %1, 0
17 %6 = select i1 %4, i64 %y, i64 %5
21 define i64 @sel_false_val_is_a_masked_shl_of_true_val2(i32 %x, i64 %y) {
22 ; CHECK-LABEL: @sel_false_val_is_a_masked_shl_of_true_val2(
23 ; CHECK-NEXT: [[TMP1:%.*]] = shl i32 [[X:%.*]], 2
24 ; CHECK-NEXT: [[TMP2:%.*]] = and i32 [[TMP1]], 60
25 ; CHECK-NEXT: [[TMP3:%.*]] = zext i32 [[TMP2]] to i64
26 ; CHECK-NEXT: [[TMP4:%.*]] = ashr i64 [[Y:%.*]], [[TMP3]]
27 ; CHECK-NEXT: ret i64 [[TMP4]]
30 %2 = shl nuw nsw i32 %1, 2
31 %3 = zext i32 %2 to i64
32 %4 = icmp eq i32 %2, 0
34 %6 = select i1 %4, i64 %y, i64 %5
38 define i64 @sel_false_val_is_a_masked_lshr_of_true_val1(i32 %x, i64 %y) {
39 ; CHECK-LABEL: @sel_false_val_is_a_masked_lshr_of_true_val1(
40 ; CHECK-NEXT: [[TMP1:%.*]] = lshr i32 [[X:%.*]], 2
41 ; CHECK-NEXT: [[TMP2:%.*]] = and i32 [[TMP1]], 15
42 ; CHECK-NEXT: [[TMP3:%.*]] = zext i32 [[TMP2]] to i64
43 ; CHECK-NEXT: [[TMP4:%.*]] = ashr i64 [[Y:%.*]], [[TMP3]]
44 ; CHECK-NEXT: ret i64 [[TMP4]]
48 %3 = zext i32 %2 to i64
49 %4 = icmp eq i32 %1, 0
51 %6 = select i1 %4, i64 %y, i64 %5
55 define i64 @sel_false_val_is_a_masked_lshr_of_true_val2(i32 %x, i64 %y) {
56 ; CHECK-LABEL: @sel_false_val_is_a_masked_lshr_of_true_val2(
57 ; CHECK-NEXT: [[TMP1:%.*]] = lshr i32 [[X:%.*]], 2
58 ; CHECK-NEXT: [[TMP2:%.*]] = and i32 [[TMP1]], 15
59 ; CHECK-NEXT: [[TMP3:%.*]] = zext i32 [[TMP2]] to i64
60 ; CHECK-NEXT: [[TMP4:%.*]] = ashr i64 [[Y:%.*]], [[TMP3]]
61 ; CHECK-NEXT: ret i64 [[TMP4]]
65 %3 = zext i32 %2 to i64
66 %4 = icmp eq i32 %2, 0
68 %6 = select i1 %4, i64 %y, i64 %5
72 define i64 @sel_false_val_is_a_masked_ashr_of_true_val1(i32 %x, i64 %y) {
73 ; CHECK-LABEL: @sel_false_val_is_a_masked_ashr_of_true_val1(
74 ; CHECK-NEXT: [[TMP1:%.*]] = ashr i32 [[X:%.*]], 2
75 ; CHECK-NEXT: [[TMP2:%.*]] = and i32 [[TMP1]], -536870897
76 ; CHECK-NEXT: [[TMP3:%.*]] = zext i32 [[TMP2]] to i64
77 ; CHECK-NEXT: [[TMP4:%.*]] = ashr i64 [[Y:%.*]], [[TMP3]]
78 ; CHECK-NEXT: ret i64 [[TMP4]]
80 %1 = and i32 %x, -2147483588
82 %3 = zext i32 %2 to i64
83 %4 = icmp eq i32 %1, 0
85 %6 = select i1 %4, i64 %y, i64 %5
89 define i64 @sel_false_val_is_a_masked_ashr_of_true_val2(i32 %x, i64 %y) {
90 ; CHECK-LABEL: @sel_false_val_is_a_masked_ashr_of_true_val2(
91 ; CHECK-NEXT: [[TMP1:%.*]] = ashr i32 [[X:%.*]], 2
92 ; CHECK-NEXT: [[TMP2:%.*]] = and i32 [[TMP1]], -536870897
93 ; CHECK-NEXT: [[TMP3:%.*]] = zext i32 [[TMP2]] to i64
94 ; CHECK-NEXT: [[TMP4:%.*]] = ashr i64 [[Y:%.*]], [[TMP3]]
95 ; CHECK-NEXT: ret i64 [[TMP4]]
97 %1 = and i32 %x, -2147483588
99 %3 = zext i32 %2 to i64
100 %4 = icmp eq i32 %2, 0
102 %6 = select i1 %4, i64 %y, i64 %5