[llvm-commits] [llvm] r157701 - in /llvm/trunk: include/llvm/Analysis/ScalarEvolution.h lib/Analysis/ScalarEvolution.cpp test/Transforms/IndVarSimplify/ult-sub-to-eq.ll
Benjamin Kramer
benny.kra at googlemail.com
Wed May 30 11:44:32 PDT 2012
On 30.05.2012, at 20:39, Eli Friedman wrote:
> On Wed, May 30, 2012 at 11:32 AM, Benjamin Kramer
> <benny.kra at googlemail.com> wrote:
>> Author: d0k
>> Date: Wed May 30 13:32:23 2012
>> New Revision: 157701
>>
>> URL: http://llvm.org/viewvc/llvm-project?rev=157701&view=rev
>> Log:
>> Teach SCEV's icmp simplification logic that a-b == 0 is equivalent to a == b.
>>
>> This also required making recursive simplifications until
>> nothing changes or a hard limit (currently 3) is hit.
>>
>> With the simplification in place indvars can canonicalize
>> loops of the form
>> for (unsigned i = 0; i < a-b; ++i)
>> into
>> for (unsigned i = 0; i != a-b; ++i)
>> which used to fail because SCEV created a weird umax expr
>> for the backedge taken count.
>>
>> Added:
>> llvm/trunk/test/Transforms/IndVarSimplify/ult-sub-to-eq.ll
>> Modified:
>> llvm/trunk/include/llvm/Analysis/ScalarEvolution.h
>> llvm/trunk/lib/Analysis/ScalarEvolution.cpp
>>
>> Modified: llvm/trunk/include/llvm/Analysis/ScalarEvolution.h
>> URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/Analysis/ScalarEvolution.h?rev=157701&r1=157700&r2=157701&view=diff
>> ==============================================================================
>> --- llvm/trunk/include/llvm/Analysis/ScalarEvolution.h (original)
>> +++ llvm/trunk/include/llvm/Analysis/ScalarEvolution.h Wed May 30 13:32:23 2012
>> @@ -837,7 +837,8 @@
>> ///
>> bool SimplifyICmpOperands(ICmpInst::Predicate &Pred,
>> const SCEV *&LHS,
>> - const SCEV *&RHS);
>> + const SCEV *&RHS,
>> + unsigned Depth = 0);
>>
>> /// getLoopDisposition - Return the "disposition" of the given SCEV with
>> /// respect to the given loop.
>>
>> Modified: llvm/trunk/lib/Analysis/ScalarEvolution.cpp
>> URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Analysis/ScalarEvolution.cpp?rev=157701&r1=157700&r2=157701&view=diff
>> ==============================================================================
>> --- llvm/trunk/lib/Analysis/ScalarEvolution.cpp (original)
>> +++ llvm/trunk/lib/Analysis/ScalarEvolution.cpp Wed May 30 13:32:23 2012
>> @@ -5605,9 +5605,14 @@
>> /// predicate Pred. Return true iff any changes were made.
>> ///
>> bool ScalarEvolution::SimplifyICmpOperands(ICmpInst::Predicate &Pred,
>> - const SCEV *&LHS, const SCEV *&RHS) {
>> + const SCEV *&LHS, const SCEV *&RHS,
>> + unsigned Depth) {
>> bool Changed = false;
>>
>> + // If we hit the max recursion limit bail out.
>> + if (Depth >= 3)
>> + return false;
>> +
>> // Canonicalize a constant to the right side.
>> if (const SCEVConstant *LHSC = dyn_cast<SCEVConstant>(LHS)) {
>> // Check for both operands constant.
>> @@ -5645,6 +5650,15 @@
>> default: llvm_unreachable("Unexpected ICmpInst::Predicate value!");
>> case ICmpInst::ICMP_EQ:
>> case ICmpInst::ICMP_NE:
>> + // Fold ((-1) * %a) + %b == 0 (equivalent to %b-%a == 0) into %a == %b.
>> + if (!RA)
>> + if (const SCEVAddExpr *AE = dyn_cast<SCEVAddExpr>(LHS))
>> + if (const SCEVMulExpr *ME = dyn_cast<SCEVMulExpr>(AE->getOperand(0)))
>> + if (ME->getOperand(0)->isAllOnesValue()) {
>> + RHS = AE->getOperand(1);
>> + LHS = ME->getOperand(1);
>> + Changed = true;
>
> Err, SCEVAddExpr can have more than 2 operands...
Sigh, I wish SCEV would match IR more closely. Limited it to 2 operands in r157704.
- Ben
More information about the llvm-commits
mailing list