llvm.org GIT mirror llvm / c65c747
Fold icmp ugt (udiv X, Y), X to false. Spotted by my super-optimizer in 186.crafty. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@143209 91177308-0d34-0410-b5e6-96231b3b80d8 Duncan Sands 7 years ago
2 changed file(s) with 36 addition(s) and 0 deletion(s). Raw diff Collapse all Expand all
15731573 // 'srem x, CI2' produces (-|CI2|, |CI2|).
15741574 Upper = CI2->getValue().abs();
15751575 Lower = (-Upper) + 1;
1576 } else if (match(LHS, m_UDiv(m_ConstantInt(CI2), m_Value()))) {
1577 // 'udiv CI2, x' produces [0, CI2].
1578 Upper = CI2->getValue();
15761579 } else if (match(LHS, m_UDiv(m_Value(), m_ConstantInt(CI2)))) {
15771580 // 'udiv x, CI2' produces [0, UINT_MAX / CI2].
15781581 APInt NegOne = APInt::getAllOnesValue(Width);
18771880 case ICmpInst::ICMP_ULE:
18781881 return getFalse(ITy);
18791882 }
1883 }
1884
1885 // x udiv y <=u x.
1886 if (LBO && match(LBO, m_UDiv(m_Specific(RHS), m_Value()))) {
1887 // icmp pred (X /u Y), X
1888 if (Pred == ICmpInst::ICMP_UGT)
1889 return getFalse(ITy);
1890 if (Pred == ICmpInst::ICMP_ULE)
1891 return getTrue(ITy);
18801892 }
18811893
18821894 if (MaxRecurse && LBO && RBO && LBO->getOpcode() == RBO->getOpcode() &&
299299 ; CHECK: ret i1 true
300300 }
301301
302 define i1 @udiv3(i32 %X, i32 %Y) {
303 ; CHECK: @udiv3
304 %A = udiv i32 %X, %Y
305 %C = icmp ugt i32 %A, %X
306 ret i1 %C
307 ; CHECK: ret i1 false
308 }
309
310 define i1 @udiv4(i32 %X, i32 %Y) {
311 ; CHECK: @udiv4
312 %A = udiv i32 %X, %Y
313 %C = icmp ule i32 %A, %X
314 ret i1 %C
315 ; CHECK: ret i1 true
316 }
317
318 define i1 @udiv5(i32 %X) {
319 ; CHECK: @udiv5
320 %A = udiv i32 123, %X
321 %C = icmp ugt i32 %A, 124
322 ret i1 %C
323 ; CHECK: ret i1 false
324 }
325
302326 define i1 @sdiv1(i32 %X) {
303327 ; CHECK: @sdiv1
304328 %A = sdiv i32 %X, 1000000