llvm.org GIT mirror llvm / 88cd0aa
Optimize "icmp pred (urem X, Y), Y" --> true/false depending on pred. There's more work to do here, "icmp ult (urem X, 10), 11" doesn't optimize away yet. Fixes example 3 from PR9343! git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@126741 91177308-0d34-0410-b5e6-96231b3b80d8 Nick Lewycky 8 years ago
2 changed file(s) with 34 addition(s) and 0 deletion(s). Raw diff Collapse all Expand all
14331433 return ConstantInt::getTrue(CI->getContext());
14341434 break;
14351435 }
1436
1437 // TODO: integer div and rem with constant RHS all produce values in a
1438 // constant range. We should check whether the comparison is a tautology.
14361439 }
14371440
14381441 // Compare of cast, for example (zext X) != 0 -> X != 0
16401643 Value *Z = (C == A || C == B) ? D : C;
16411644 if (Value *V = SimplifyICmpInst(Pred, Y, Z, TD, DT, MaxRecurse-1))
16421645 return V;
1646 }
1647 }
1648
1649 if (LBO && match(LBO, m_URem(m_Value(), m_Specific(RHS)))) {
1650 switch (Pred) {
1651 default:
1652 break;
1653 case ICmpInst::ICMP_EQ:
1654 case ICmpInst::ICMP_UGT:
1655 case ICmpInst::ICMP_UGE:
1656 return ConstantInt::getFalse(RHS->getContext());
1657 case ICmpInst::ICMP_NE:
1658 case ICmpInst::ICMP_ULT:
1659 case ICmpInst::ICMP_ULE:
1660 return ConstantInt::getTrue(RHS->getContext());
16431661 }
16441662 }
16451663
186186 ret i1 %c
187187 ; CHECK: ret i1 %cond
188188 }
189
190 define i1 @urem1(i32 %X, i32 %Y) {
191 ; CHECK: @urem1
192 %A = urem i32 %X, %Y
193 %B = icmp ult i32 %A, %Y
194 ret i1 %B
195 ; CHECK: ret i1 true
196 }
197
198 define i1 @urem2(i32 %X, i32 %Y) {
199 ; CHECK: @urem2
200 %A = urem i32 %X, %Y
201 %B = icmp eq i32 %A, %Y
202 ret i1 %B
203 ; CHECK ret i1 false
204 }