Details
Diff Detail
- Repository
- rL LLVM
Event Timeline
lib/Transforms/Utils/SimplifyIndVar.cpp | ||
---|---|---|
551 | Ok, will do | |
557 | You means we gain something if we can "simplify" the IV user from a SCEVAddRec to a SCEVUnknown?* SE->getSCEV(I); may directly return an SCEUnknown, so we need to compare the new LLVM Value and the original one. |
lib/Transforms/Utils/SimplifyIndVar.cpp | ||
---|---|---|
557 | Rather than try to check for equality, you can just check whether the SCEVUnknown is loop-invariant. |
lib/Transforms/Utils/SimplifyIndVar.cpp | ||
---|---|---|
557 | This sounds great |
lib/Transforms/Utils/SimplifyIndVar.cpp | ||
---|---|---|
576–577 | Should we only expand SCEVConstant and SCEVUnknown? If we should expand all SCEV that is Loop Invariant, should we make the SCEVExpander global, such that we have a global "InsertedExpressions" map (in the SCEVExpander) to remember the SCEV expression that we expanded? |
Looks like I need to pass the SCEVExpander from the IndVarSimpilfy pass to coordinate SCEV rewrite, otherwise we will fail test/Transforms/IndVarSimplify/pr20680.ll
lib/Transforms/Utils/SimplifyIndVar.cpp | ||
---|---|---|
574 | We may only want to do the replace if S is invariant of the IV's Loop, which may be different from "L" which is the innermost loop that contains the IV user |
lib/Transforms/Utils/SimplifyIndVar.cpp | ||
---|---|---|
576–577 | SCEVExpander figure out the correct place by itself (at least in test4 of test/Transforms/IndVarSimplify/replace-iv-with-loop-invariant.ll), otherwise we need to find the preheader (and fallback to I if there is no preheader) | |
test/Transforms/IndVarSimplify/replace-iv-with-loop-invariant.ll | ||
84 ↗ | (On Diff #117271) | Here the SCEVExpander expand the expression before the loop (before the phi) |
lib/Transforms/Utils/SimplifyIndVar.cpp | ||
---|---|---|
574 | Yes, this make sense. I did some experiments and we may want to actually write: if (!SE->isLoopInvariant(S, IV's Loop) || !SE->isLoopInvariant(S, IV User's Loop)) If IV's Loop do not contains IV User's Loop |
lib/Transforms/Utils/SimplifyIndVar.cpp | ||
---|---|---|
574 | Given a function in LCSSA form, I don't think this relevant? But feel free to prove me wrong. :) |
lib/Transforms/Utils/SimplifyIndVar.cpp | ||
---|---|---|
574 | Not sure if we assume LCSSA (or SCEV could see through it), I hit some crash when I just test 'if (!SE->isLoopInvariant(S, IV's Loop))' and it turned out that IV's Loop do not contain IV's user. I will find those cases |
lib/Transforms/Utils/SimplifyIndVar.cpp | ||
---|---|---|
575 | Maybe we should not push IV users in pushIVUsers at all if IV users do not in the IV loop (e.g. LCSSA phi) |
lib/Transforms/Utils/SimplifyIndVar.cpp | ||
---|---|---|
575 | Yeah, that makes sense; we have special handling for exit values in IndVarSimplify::rewriteLoopExitValues. |
lib/Transforms/Utils/SimplifyIndVar.cpp | ||
---|---|---|
576–577 | End comments with a period (here and also below). |
lib/Transforms/Utils/SimplifyIndVar.cpp | ||
---|---|---|
572 | SE->getSCEVAtScope(SE->getSCEV(I), LI->getLoopFor(I->getParent())) should be equivalent to SE->getSCEV(I). The point of getSCEVAtScope is to compute the value of a SCEV outside of its associated loop (the exit value). Sorry, I should have spotted this earlier. |
lib/Transforms/Utils/SimplifyIndVar.cpp | ||
---|---|---|
572 | Thanks for pointing this out, I will update the patch |
Could you use SCEVExpander rather than writing out the cast logic here? I'm not sure this covers all the relevant cases.