llvm.org GIT mirror llvm / 891ec6d
InstSimplify: shl nsw/nuw undef, %V -> undef We can always choose an value for undef which might cause %V to shift out an important bit except for one case, when %V is zero. However, shl behaves like an identity function when the right hand side is zero. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@224405 91177308-0d34-0410-b5e6-96231b3b80d8 David Majnemer 4 years ago
2 changed file(s) with 35 addition(s) and 13 deletion(s). Raw diff Collapse all Expand all
13371337 if (Op0 == Op1)
13381338 return Constant::getNullValue(Op0->getType());
13391339
1340 // undef >> X -> 0
1341 // undef >> X -> undef (if it's exact)
1342 if (match(Op0, m_Undef()))
1343 return isExact ? Op0 : Constant::getNullValue(Op0->getType());
1344
13401345 // The low bit cannot be shifted out of an exact shift if it is set.
13411346 if (isExact) {
13421347 unsigned BitWidth = Op0->getType()->getScalarSizeInBits();
13591364 return V;
13601365
13611366 // undef << X -> 0
1367 // undef << X -> undef if (if it's NSW/NUW)
13621368 if (match(Op0, m_Undef()))
1363 return Constant::getNullValue(Op0->getType());
1369 return isNSW || isNUW ? Op0 : Constant::getNullValue(Op0->getType());
13641370
13651371 // (X >> A) << A -> X
13661372 Value *X;
13841390 if (Value *V = SimplifyRightShift(Instruction::LShr, Op0, Op1, isExact, Q,
13851391 MaxRecurse))
13861392 return V;
1387
1388 // undef >>l X -> 0
1389 // undef >>l X -> undef (if it's exact)
1390 if (match(Op0, m_Undef()))
1391 return isExact ? UndefValue::get(Op0->getType())
1392 : Constant::getNullValue(Op0->getType());
13931393
13941394 // (X << A) >> A -> X
13951395 Value *X;
14201420 // all ones >>a X -> all ones
14211421 if (match(Op0, m_AllOnes()))
14221422 return Op0;
1423
1424 // undef >>a X -> 0
1425 // undef >>a X -> undef (if it's exact)
1426 if (match(Op0, m_Undef()))
1427 return isExact ? UndefValue::get(Op0->getType())
1428 : Constant::getNullValue(Op0->getType());
14291423
14301424 // (X << A) >> A -> X
14311425 Value *X;
215215 %b = shl i32 0, undef
216216 ret i32 %b
217217 }
218
219 ; CHECK-LABEL: @test28
220 ; CHECK: ret i32 undef
221 define i32 @test28(i32 %a) {
222 %b = shl nsw i32 undef, %a
223 ret i32 %b
224 }
225
226 ; CHECK-LABEL: @test29
227 ; CHECK: ret i32 undef
228 define i32 @test29(i32 %a) {
229 %b = shl nuw i32 undef, %a
230 ret i32 %b
231 }
232
233 ; CHECK-LABEL: @test30
234 ; CHECK: ret i32 undef
235 define i32 @test30(i32 %a) {
236 %b = shl nsw nuw i32 undef, %a
237 ret i32 %b
238 }
239
240 ; CHECK-LABEL: @test31
241 ; CHECK: ret i32 0
242 define i32 @test31(i32 %a) {
243 %b = shl i32 undef, %a
244 ret i32 %b
245 }