Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion llvm/lib/Transforms/Utils/LoopPeel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1257,7 +1257,11 @@ bool llvm::peelLoop(Loop *L, unsigned PeelCount, bool PeelLast, LoopInfo *LI,
// Now adjust users of the original exit values by replacing them with the
// exit value from the peeled iteration and remove them.
for (const auto &[P, E] : ExitValues) {
P->replaceAllUsesWith(isa<Constant>(E) ? E : &*VMap.lookup(E));
Instruction *ExitInst = dyn_cast<Instruction>(E);
if (ExitInst && L->contains(ExitInst))
P->replaceAllUsesWith(&*VMap[ExitInst]);
else
P->replaceAllUsesWith(E);
P->eraseFromParent();
}
formLCSSA(*L, DT, LI, SE);
Expand Down
41 changes: 41 additions & 0 deletions llvm/test/Transforms/LoopUnroll/unroll-and-peel-last-iteration.ll
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,47 @@ exit:
ret i32 %1
}

; Test case for https://github.com/llvm/llvm-project/issues/142895.

define i32 @pr142895_exit_value_is_arg(i32 %arg) {
entry:
br label %for.cond.preheader

for.cond.preheader:
%indvar = phi i32 [ 0, %entry ], [ %inc, %for.cond.preheader ]
%cmp1 = icmp eq i32 %indvar, 32
%sel = select i1 %cmp1, i32 0, i32 0
%sub = sub i32 0, 0
%xor = xor i32 0, 0
%inc = add i32 %indvar, 1
%exitcond = icmp ne i32 %inc, 33
br i1 %exitcond, label %for.cond.preheader, label %for.cond.cleanup

for.cond.cleanup:
%exit.lcssa = phi i32 [ %arg, %for.cond.preheader ]
ret i32 %exit.lcssa
}

define i32 @pr142895_exit_value_is_inst(i32 %arg) {
entry:
%mul = mul i32 %arg, 7
br label %for.cond.preheader

for.cond.preheader:
%indvar = phi i32 [ 0, %entry ], [ %inc, %for.cond.preheader ]
%cmp1 = icmp eq i32 %indvar, 32
%sel = select i1 %cmp1, i32 0, i32 0
%sub = sub i32 0, 0
%xor = xor i32 0, 0
%inc = add i32 %indvar, 1
%exitcond = icmp ne i32 %inc, 33
br i1 %exitcond, label %for.cond.preheader, label %for.cond.cleanup

for.cond.cleanup:
%exit.lcssa = phi i32 [ %mul, %for.cond.preheader ]
ret i32 %exit.lcssa
}

declare void @foo(i32)
;.
; CHECK: [[LOOP0]] = distinct !{[[LOOP0]], [[META1:![0-9]+]]}
Expand Down
Loading