|
| 1 | +; NOTE: Assertions have been autogenerated by utils/update_test_checks.py UTC_ARGS: --version 5 |
| 2 | +; RUN: opt -passes=instcombine -S %s | FileCheck %s |
| 3 | + |
| 4 | +define i8 @select_icmp_eq_pow2(i8 %x) { |
| 5 | +; CHECK-LABEL: define i8 @select_icmp_eq_pow2( |
| 6 | +; CHECK-SAME: i8 [[X:%.*]]) { |
| 7 | +; CHECK-NEXT: [[SEL:%.*]] = and i8 [[X]], -5 |
| 8 | +; CHECK-NEXT: ret i8 [[SEL]] |
| 9 | +; |
| 10 | + %and = and i8 %x, 4 |
| 11 | + %icmp = icmp eq i8 %and, 0 |
| 12 | + %xor = xor i8 %x, 4 |
| 13 | + %sel = select i1 %icmp, i8 %x, i8 %xor |
| 14 | + ret i8 %sel |
| 15 | +} |
| 16 | + |
| 17 | +define i8 @select_icmp_eq_pow2_flipped(i8 %x) { |
| 18 | +; CHECK-LABEL: define i8 @select_icmp_eq_pow2_flipped( |
| 19 | +; CHECK-SAME: i8 [[X:%.*]]) { |
| 20 | +; CHECK-NEXT: [[SEL:%.*]] = or i8 [[X]], 4 |
| 21 | +; CHECK-NEXT: ret i8 [[SEL]] |
| 22 | +; |
| 23 | + %and = and i8 %x, 4 |
| 24 | + %icmp = icmp eq i8 %and, 0 |
| 25 | + %xor = xor i8 %x, 4 |
| 26 | + %sel = select i1 %icmp, i8 %xor, i8 %x |
| 27 | + ret i8 %sel |
| 28 | +} |
| 29 | + |
| 30 | +define i8 @select_icmp_eq_not_pow2(i8 %x) { |
| 31 | +; CHECK-LABEL: define i8 @select_icmp_eq_not_pow2( |
| 32 | +; CHECK-SAME: i8 [[X:%.*]]) { |
| 33 | +; CHECK-NEXT: [[AND:%.*]] = and i8 [[X]], 5 |
| 34 | +; CHECK-NEXT: [[ICMP:%.*]] = icmp eq i8 [[AND]], 0 |
| 35 | +; CHECK-NEXT: [[XOR:%.*]] = xor i8 [[X]], 5 |
| 36 | +; CHECK-NEXT: [[SEL:%.*]] = select i1 [[ICMP]], i8 [[X]], i8 [[XOR]] |
| 37 | +; CHECK-NEXT: ret i8 [[SEL]] |
| 38 | +; |
| 39 | + %and = and i8 %x, 5 |
| 40 | + %icmp = icmp eq i8 %and, 0 |
| 41 | + %xor = xor i8 %x, 5 |
| 42 | + %sel = select i1 %icmp, i8 %x, i8 %xor |
| 43 | + ret i8 %sel |
| 44 | +} |
| 45 | + |
| 46 | +define i8 @select_icmp_ne_pow2(i8 %x) { |
| 47 | +; CHECK-LABEL: define i8 @select_icmp_ne_pow2( |
| 48 | +; CHECK-SAME: i8 [[X:%.*]]) { |
| 49 | +; CHECK-NEXT: [[SEL:%.*]] = and i8 [[X]], -5 |
| 50 | +; CHECK-NEXT: ret i8 [[SEL]] |
| 51 | +; |
| 52 | + %and = and i8 %x, 4 |
| 53 | + %icmp = icmp ne i8 %and, 0 |
| 54 | + %xor = xor i8 %x, 4 |
| 55 | + %sel = select i1 %icmp, i8 %xor, i8 %x |
| 56 | + ret i8 %sel |
| 57 | +} |
| 58 | + |
| 59 | +define i8 @select_icmp_ne_pow2_flipped(i8 %x) { |
| 60 | +; CHECK-LABEL: define i8 @select_icmp_ne_pow2_flipped( |
| 61 | +; CHECK-SAME: i8 [[X:%.*]]) { |
| 62 | +; CHECK-NEXT: [[SEL:%.*]] = or i8 [[X]], 4 |
| 63 | +; CHECK-NEXT: ret i8 [[SEL]] |
| 64 | +; |
| 65 | + %and = and i8 %x, 4 |
| 66 | + %icmp = icmp ne i8 %and, 0 |
| 67 | + %xor = xor i8 %x, 4 |
| 68 | + %sel = select i1 %icmp, i8 %x, i8 %xor |
| 69 | + ret i8 %sel |
| 70 | +} |
| 71 | + |
| 72 | +define i8 @select_icmp_ne_not_pow2(i8 %x) { |
| 73 | +; CHECK-LABEL: define i8 @select_icmp_ne_not_pow2( |
| 74 | +; CHECK-SAME: i8 [[X:%.*]]) { |
| 75 | +; CHECK-NEXT: [[AND:%.*]] = and i8 [[X]], 5 |
| 76 | +; CHECK-NEXT: [[ICMP_NOT:%.*]] = icmp eq i8 [[AND]], 0 |
| 77 | +; CHECK-NEXT: [[XOR:%.*]] = xor i8 [[X]], 5 |
| 78 | +; CHECK-NEXT: [[SEL:%.*]] = select i1 [[ICMP_NOT]], i8 [[X]], i8 [[XOR]] |
| 79 | +; CHECK-NEXT: ret i8 [[SEL]] |
| 80 | +; |
| 81 | + %and = and i8 %x, 5 |
| 82 | + %icmp = icmp ne i8 %and, 0 |
| 83 | + %xor = xor i8 %x, 5 |
| 84 | + %sel = select i1 %icmp, i8 %xor, i8 %x |
| 85 | + ret i8 %sel |
| 86 | +} |
| 87 | + |
| 88 | +define i8 @select_icmp_slt_zero_smin(i8 %x) { |
| 89 | +; CHECK-LABEL: define i8 @select_icmp_slt_zero_smin( |
| 90 | +; CHECK-SAME: i8 [[X:%.*]]) { |
| 91 | +; CHECK-NEXT: [[SEL:%.*]] = or i8 [[X]], -128 |
| 92 | +; CHECK-NEXT: ret i8 [[SEL]] |
| 93 | +; |
| 94 | + %icmp = icmp slt i8 %x, 0 |
| 95 | + %xor = xor i8 %x, -128 |
| 96 | + %sel = select i1 %icmp, i8 %x, i8 %xor |
| 97 | + ret i8 %sel |
| 98 | +} |
| 99 | + |
| 100 | +define i8 @select_icmp_slt_zero_smin_flipped(i8 %x) { |
| 101 | +; CHECK-LABEL: define i8 @select_icmp_slt_zero_smin_flipped( |
| 102 | +; CHECK-SAME: i8 [[X:%.*]]) { |
| 103 | +; CHECK-NEXT: [[SEL:%.*]] = and i8 [[X]], 127 |
| 104 | +; CHECK-NEXT: ret i8 [[SEL]] |
| 105 | +; |
| 106 | + %icmp = icmp slt i8 %x, 0 |
| 107 | + %xor = xor i8 %x, -128 |
| 108 | + %sel = select i1 %icmp, i8 %xor, i8 %x |
| 109 | + ret i8 %sel |
| 110 | +} |
| 111 | + |
| 112 | +define i8 @select_icmp_slt_not_zero(i8 %x) { |
| 113 | +; CHECK-LABEL: define i8 @select_icmp_slt_not_zero( |
| 114 | +; CHECK-SAME: i8 [[X:%.*]]) { |
| 115 | +; CHECK-NEXT: [[ICMP:%.*]] = icmp slt i8 [[X]], 1 |
| 116 | +; CHECK-NEXT: [[XOR:%.*]] = xor i8 [[X]], -128 |
| 117 | +; CHECK-NEXT: [[SEL:%.*]] = select i1 [[ICMP]], i8 [[X]], i8 [[XOR]] |
| 118 | +; CHECK-NEXT: ret i8 [[SEL]] |
| 119 | +; |
| 120 | + %icmp = icmp slt i8 %x, 1 |
| 121 | + %xor = xor i8 %x, -128 |
| 122 | + %sel = select i1 %icmp, i8 %x, i8 %xor |
| 123 | + ret i8 %sel |
| 124 | +} |
| 125 | + |
| 126 | +define i8 @select_icmp_slt_not_smin(i8 %x) { |
| 127 | +; CHECK-LABEL: define i8 @select_icmp_slt_not_smin( |
| 128 | +; CHECK-SAME: i8 [[X:%.*]]) { |
| 129 | +; CHECK-NEXT: [[ICMP:%.*]] = icmp slt i8 [[X]], 0 |
| 130 | +; CHECK-NEXT: [[XOR:%.*]] = xor i8 [[X]], -127 |
| 131 | +; CHECK-NEXT: [[SEL:%.*]] = select i1 [[ICMP]], i8 [[X]], i8 [[XOR]] |
| 132 | +; CHECK-NEXT: ret i8 [[SEL]] |
| 133 | +; |
| 134 | + %icmp = icmp slt i8 %x, 0 |
| 135 | + %xor = xor i8 %x, -127 |
| 136 | + %sel = select i1 %icmp, i8 %x, i8 %xor |
| 137 | + ret i8 %sel |
| 138 | +} |
| 139 | + |
| 140 | +define i8 @select_icmp_sgt_allones_smin(i8 %x) { |
| 141 | +; CHECK-LABEL: define i8 @select_icmp_sgt_allones_smin( |
| 142 | +; CHECK-SAME: i8 [[X:%.*]]) { |
| 143 | +; CHECK-NEXT: [[SEL:%.*]] = and i8 [[X]], 127 |
| 144 | +; CHECK-NEXT: ret i8 [[SEL]] |
| 145 | +; |
| 146 | + %icmp = icmp sgt i8 %x, 255 |
| 147 | + %xor = xor i8 %x, -128 |
| 148 | + %sel = select i1 %icmp, i8 %x, i8 %xor |
| 149 | + ret i8 %sel |
| 150 | +} |
| 151 | + |
| 152 | +define i8 @select_icmp_sgt_allones_smin_flipped(i8 %x) { |
| 153 | +; CHECK-LABEL: define i8 @select_icmp_sgt_allones_smin_flipped( |
| 154 | +; CHECK-SAME: i8 [[X:%.*]]) { |
| 155 | +; CHECK-NEXT: [[SEL:%.*]] = or i8 [[X]], -128 |
| 156 | +; CHECK-NEXT: ret i8 [[SEL]] |
| 157 | +; |
| 158 | + %icmp = icmp sgt i8 %x, 255 |
| 159 | + %xor = xor i8 %x, -128 |
| 160 | + %sel = select i1 %icmp, i8 %xor, i8 %x |
| 161 | + ret i8 %sel |
| 162 | +} |
| 163 | + |
| 164 | +define i8 @select_icmp_sgt_not_allones(i8 %x) { |
| 165 | +; CHECK-LABEL: define i8 @select_icmp_sgt_not_allones( |
| 166 | +; CHECK-SAME: i8 [[X:%.*]]) { |
| 167 | +; CHECK-NEXT: [[ICMP:%.*]] = icmp sgt i8 [[X]], -2 |
| 168 | +; CHECK-NEXT: [[XOR:%.*]] = xor i8 [[X]], -128 |
| 169 | +; CHECK-NEXT: [[SEL:%.*]] = select i1 [[ICMP]], i8 [[X]], i8 [[XOR]] |
| 170 | +; CHECK-NEXT: ret i8 [[SEL]] |
| 171 | +; |
| 172 | + %icmp = icmp sgt i8 %x, 254 |
| 173 | + %xor = xor i8 %x, -128 |
| 174 | + %sel = select i1 %icmp, i8 %x, i8 %xor |
| 175 | + ret i8 %sel |
| 176 | +} |
| 177 | + |
| 178 | +define i8 @select_icmp_sgt_not_smin(i8 %x) { |
| 179 | +; CHECK-LABEL: define i8 @select_icmp_sgt_not_smin( |
| 180 | +; CHECK-SAME: i8 [[X:%.*]]) { |
| 181 | +; CHECK-NEXT: [[XOR:%.*]] = xor i8 [[X]], -127 |
| 182 | +; CHECK-NEXT: [[ICMP1:%.*]] = icmp slt i8 [[X]], 0 |
| 183 | +; CHECK-NEXT: [[SEL:%.*]] = select i1 [[ICMP1]], i8 [[XOR]], i8 [[X]] |
| 184 | +; CHECK-NEXT: ret i8 [[SEL]] |
| 185 | +; |
| 186 | + %icmp = icmp sgt i8 %x, 255 |
| 187 | + %xor = xor i8 %x, -127 |
| 188 | + %sel = select i1 %icmp, i8 %x, i8 %xor |
| 189 | + ret i8 %sel |
| 190 | +} |
0 commit comments