llvm.org GIT mirror llvm / dae3654
[InstSimplify] Optimize away udivs in the presence of range metadata We know that udiv %V, C can be optimized away to 0 if %V is ult C. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@291296 91177308-0d34-0410-b5e6-96231b3b80d8 David Majnemer 2 years ago
2 changed file(s) with 25 addition(s) and 0 deletion(s). Raw diff Collapse all Expand all
11041104 unsigned MaxRecurse) {
11051105 if (Value *V = SimplifyDiv(Instruction::UDiv, Op0, Op1, Q, MaxRecurse))
11061106 return V;
1107
1108 // udiv %V, C -> 0 if %V < C
1109 if (MaxRecurse) {
1110 if (Constant *C = dyn_cast_or_null(SimplifyICmpInst(
1111 ICmpInst::ICMP_ULT, Op0, Op1, Q, MaxRecurse - 1))) {
1112 if (C->isAllOnesValue()) {
1113 return Constant::getNullValue(Op0->getType());
1114 }
1115 }
1116 }
11071117
11081118 return nullptr;
11091119 }
0 ; RUN: opt < %s -instsimplify -S | FileCheck %s
1
2 declare i32 @external()
3
4 define i32 @div1() {
5 ; CHECK-LABEL: @div1(
6 ; CHECK: [[CALL:%.*]] = call i32 @external(), !range !0
7 ; CHECK-NEXT: ret i32 0
8 ;
9 %call = call i32 @external(), !range !0
10 %urem = udiv i32 %call, 3
11 ret i32 %urem
12 }
13
14 !0 = !{i32 0, i32 3}