Fix bug exposed by https://reviews.llvm.org/D125990, rewriteLoopExitValues calls InductionDescriptor::isInductionPHI which requires the PHI node to have an incoming edge from the loop preheader. This adds checks before calling InductionDescriptor::isInductionPHI to see that the loop has a preheader. Also did some refactoring.
Details
- Reviewers
Meinersbur - Group Reviewers
Restricted Project - Commits
- rG58b9666dc1a0: [LSR] Fix bug - check if loop has preheader before calling isInductionPHI
Diff Detail
Unit Tests
Event Timeline
In the interest to not block @nathanchance with a crashing compiler, I suggest to commit as soon as possible. However, a complete patch would also include a regression test.
llvm/lib/Transforms/Utils/LoopUtils.cpp | ||
---|---|---|
1249 | Please add a doxygen comment briefly describing what this is checking. |
llvm/test/Transforms/LoopStrengthReduce/remove_scev_indvars.ll | ||
---|---|---|
97–123 ↗ | (On Diff #442998) | via llvm-reduce, I was able to reduce this test case to: define void @kernfs_path_from_node() { entry: callbr void asm sideeffect "", "i"(i8* blockaddress(@kernfs_path_from_node, %while.body)) to label %asm.fallthrough [label %while.body] asm.fallthrough: ; preds = %entry br label %while.body while.body: ; preds = %while.body, %asm.fallthrough, %entry %depth.04 = phi i32 [ %inc, %while.body ], [ 0, %asm.fallthrough ], [ 0, %entry ] %inc = add i32 %depth.04, 1 br i1 false, label %while.end, label %while.body while.end: ; preds = %while.body %inc.lcssa = phi i32 [ %depth.04, %while.body ] store i32 %inc.lcssa, i32* null, align 4 ret void } |
Please mark comments as "done" in phab once they're addressed.
llvm/lib/Transforms/Utils/LoopUtils.cpp | ||
---|---|---|
1249–1259 | Regarding the comment, should any of these be sunk into the definition of InductionDescriptor::isInductionPHI? For instance, it seems like InductionDescriptor::isInductionPHI probably should check that its pointer parameters are not nullptr. Other callers of InductionDescriptor::isInductionPHI could probably then remove their nullptr checks (if they have any). Otherwise, if the !L->getLoopPreheader() and Phi->getParent() != L->getHeader() guards should NOT be sunk into the definition of InductionDescriptor::isInductionPHI, the added comment doesn't explain _why_ beyond if it is safe to call. _Why_? For instance InductionDescriptor::isFPInductionPHI has a guard if (TheLoop->getHeader() != Phi->getParent()) return false; _why_ doesn't InductionDescriptor::isInductionPHI? Perhaps it should? |
llvm/lib/Transforms/Utils/LoopUtils.cpp | ||
---|---|---|
1249–1259 | I think it makes sense that these checks could be sink into isInductionPHI. As you said, isFPInductionPHI already checks for TheLoop->getHeader() != Phi->getParent() I think this can moved into isInductionPHI. Also since isInductionPHI calls: Value *StartValue = Phi->getIncomingValueForBlock(AR->getLoop()->getLoopPreheader()); It would make sense that we check that the loop has a preheader before passing a possible null value. I can open a new PR to address this suggestion. |
llvm/lib/Transforms/Utils/LoopUtils.cpp | ||
---|---|---|
1249–1259 | SGTM; please cc me for review. |
Please add a doxygen comment briefly describing what this is checking.