llvm.org GIT mirror llvm / cf6e9a8
Simplify `x >=u x >> y` and `x >=u x udiv y` Summary: Extends InstSimplify to handle both `x >=u x >> y` and `x >=u x udiv y`. This is a folloup of rL258422 and https://github.com/rust-lang/rust/pull/30917 where llvm failed to optimize away the bounds checking in a binary search. Patch by Arthur Silva! Reviewers: sanjoy Subscribers: llvm-commits Differential Revision: https://reviews.llvm.org/D25941 git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@285228 91177308-0d34-0410-b5e6-96231b3b80d8 Sanjoy Das 2 years ago
2 changed file(s) with 43 addition(s) and 0 deletion(s). Raw diff Collapse all Expand all
28532853 if (Pred == ICmpInst::ICMP_UGT)
28542854 return getFalse(ITy);
28552855 if (Pred == ICmpInst::ICMP_ULE)
2856 return getTrue(ITy);
2857 }
2858
2859 // x >=u x >> y
2860 // x >=u x udiv y.
2861 if (RBO && (match(RBO, m_LShr(m_Specific(LHS), m_Value())) ||
2862 match(RBO, m_UDiv(m_Specific(LHS), m_Value())))) {
2863 // icmp pred X, (X op Y)
2864 if (Pred == ICmpInst::ICMP_ULT)
2865 return getFalse(ITy);
2866 if (Pred == ICmpInst::ICMP_UGE)
28562867 return getTrue(ITy);
28572868 }
28582869
408408 ; CHECK: ret i1 false
409409 }
410410
411 define i1 @lshr6(i32 %X, i32 %Y) {
412 ; CHECK-LABEL: @lshr6(
413 %A = lshr i32 %X, %Y
414 %C = icmp ult i32 %X, %A
415 ret i1 %C
416 ; CHECK: ret i1 false
417 }
418
419 define i1 @lshr7(i32 %X, i32 %Y) {
420 ; CHECK-LABEL: @lshr7(
421 %A = lshr i32 %X, %Y
422 %C = icmp uge i32 %X, %A
423 ret i1 %C
424 ; CHECK: ret i1 true
425 }
426
411427 define i1 @ashr1(i32 %x) {
412428 ; CHECK-LABEL: @ashr1(
413429 %s = ashr i32 -1, %x
580596 %C = icmp eq i32 %A, 0
581597 ret i1 %C
582598 ; CHECK: ret i1 %C
599 }
600
601 define i1 @udiv7(i32 %X, i32 %Y) {
602 ; CHECK-LABEL: @udiv7(
603 %A = udiv i32 %X, %Y
604 %C = icmp ult i32 %X, %A
605 ret i1 %C
606 ; CHECK: ret i1 false
607 }
608
609 define i1 @udiv8(i32 %X, i32 %Y) {
610 ; CHECK-LABEL: @udiv8(
611 %A = udiv i32 %X, %Y
612 %C = icmp uge i32 %X, %A
613 ret i1 %C
614 ; CHECK: ret i1 true
583615 }
584616
585617 define i1 @mul1(i32 %X) {