diff options
author | Philip Reames <preames@rivosinc.com> | 2022-08-29 11:37:42 -0700 |
---|---|---|
committer | Philip Reames <listmail@philipreames.com> | 2022-08-29 11:44:33 -0700 |
commit | c37b1a5f764380f83ba08ae0cebca2b162123eb6 (patch) | |
tree | 0275787e1e824dba6af3be93f4b00b4a945fbe30 /llvm/lib/Transforms/Utils/LoopUtils.cpp | |
parent | e1489d5e51886617a1076bc33f17737f825500e3 (diff) | |
download | llvm-c37b1a5f764380f83ba08ae0cebca2b162123eb6.zip llvm-c37b1a5f764380f83ba08ae0cebca2b162123eb6.tar.gz llvm-c37b1a5f764380f83ba08ae0cebca2b162123eb6.tar.bz2 |
[RLEV] Pick a correct insert point when incoming instruction is itself a phi node
This fixes https://github.com/llvm/llvm-project/issues/57336. It was exposed by a recent SCEV change, but appears to have been a long standing issue.
Note that the whole insert into the loop instead of a split exit edge is slightly contrived to begin with; it's there solely because IndVarSimplify preserves the CFG.
Differential Revision: https://reviews.llvm.org/D132571
Diffstat (limited to 'llvm/lib/Transforms/Utils/LoopUtils.cpp')
-rw-r--r-- | llvm/lib/Transforms/Utils/LoopUtils.cpp | 5 |
1 files changed, 4 insertions, 1 deletions
diff --git a/llvm/lib/Transforms/Utils/LoopUtils.cpp b/llvm/lib/Transforms/Utils/LoopUtils.cpp index 92f47a1..1287c3a 100644 --- a/llvm/lib/Transforms/Utils/LoopUtils.cpp +++ b/llvm/lib/Transforms/Utils/LoopUtils.cpp @@ -1395,7 +1395,10 @@ int llvm::rewriteLoopExitValues(Loop *L, LoopInfo *LI, TargetLibraryInfo *TLI, // and next SCEV may errneously get smaller cost. // Collect all the candidate PHINodes to be rewritten. - RewritePhiSet.emplace_back(PN, i, ExitValue, Inst, HighCost); + Instruction *InsertPt = + (isa<PHINode>(Inst) || isa<LandingPadInst>(Inst)) ? + &*Inst->getParent()->getFirstInsertionPt() : Inst; + RewritePhiSet.emplace_back(PN, i, ExitValue, InsertPt, HighCost); } } } |