Turns out simplifyLoopIVs sometimes returns a non-dead instruction in it's DeadInsts out param. I had done a bit of NFC cleanup which was only NFC if simplifyLoopIVs obeyed it's documentation. I'm simplfy dropping that part of the change. Commit message from try 3: Recommitting after fixing a bug found post commit. Amusingly, try 1 had been correct, and by reverting to incorporate last minute review feedback, I introduce the bug. Oops. :) Original commit message: The problem was that recursively deleting an instruction can delete instructions beyond the current iterator (via a dead phi), thus invalidating iteration. Test case added in LoopUnroll/dce.ll to cover this case. LoopUnroll does a limited DCE pass after unrolling, but if you have a chain of dead instructions, it only deletes the last one. Improve the code to recursively delete all trivially dead instructions. Differential Revision: https://reviews.llvm.org/D102511
45 lines
1.3 KiB
LLVM
45 lines
1.3 KiB
LLVM
; RUN: opt -loop-unroll -S -mtriple aarch64 -mcpu=cortex-a57 %s | FileCheck %s -check-prefix=UNROLL
|
|
; RUN: opt -loop-unroll -unroll-max-upperbound=0 -S -mtriple aarch64 -mcpu=cortex-a57 %s | FileCheck %s -check-prefix=NOUNROLL
|
|
|
|
; This IR comes from this C code:
|
|
;
|
|
; for (int i = 0; i < 4; i++) {
|
|
; if (src[i] == 1) {
|
|
; *dst = i;
|
|
; break;
|
|
; }
|
|
; }
|
|
;
|
|
; This test is meant to check that this loop is unrolled into four iterations.
|
|
; Note that the load on the last iteration is dead and thus doesn't appear in
|
|
; the output.
|
|
|
|
; UNROLL-LABEL: @test
|
|
; UNROLL: load i32, i32*
|
|
; UNROLL: load i32, i32*
|
|
; UNROLL: load i32, i32*
|
|
; UNROLL-NOT: load i32, i32*
|
|
; NOUNROLL-LABEL: @test
|
|
; NOUNROLL: load i32, i32*
|
|
; NOUNROLL-NOT: load i32, i32*
|
|
|
|
define void @test(i32* %dst, i32* %src) {
|
|
entry:
|
|
br label %for.body
|
|
|
|
for.body: ; preds = %entry, %for.body
|
|
%i = phi i32 [ 0, %entry ], [ %inc, %for.body ]
|
|
%0 = sext i32 %i to i64
|
|
%1 = getelementptr inbounds i32, i32* %src, i64 %0
|
|
%2 = load i32, i32* %1
|
|
%inc = add nsw i32 %i, 1
|
|
%cmp1 = icmp slt i32 %inc, 4
|
|
%cmp3 = icmp eq i32 %2, 1
|
|
%or.cond = and i1 %cmp3, %cmp1
|
|
br i1 %or.cond, label %for.body, label %exit
|
|
|
|
exit: ; preds = %for.body
|
|
store i32 %i, i32* %dst
|
|
ret void
|
|
}
|