diff --git a/llvm/lib/Transforms/Scalar/LoopDistribute.cpp b/llvm/lib/Transforms/Scalar/LoopDistribute.cpp --- a/llvm/lib/Transforms/Scalar/LoopDistribute.cpp +++ b/llvm/lib/Transforms/Scalar/LoopDistribute.cpp @@ -992,6 +992,7 @@ // enabled/disabled, follow that. Otherwise use the global flag. if (LDL.isForced().value_or(EnableLoopDistribute)) Changed |= LDL.processLoop(); + LAIs.clear(); } // Process each loop nest in the function. diff --git a/llvm/test/Transforms/LoopDistribute/pr59319.ll b/llvm/test/Transforms/LoopDistribute/pr59319.ll new file mode 100644 --- /dev/null +++ b/llvm/test/Transforms/LoopDistribute/pr59319.ll @@ -0,0 +1,50 @@ +; RUN: opt -passes=loop-distribute,loop-vectorize -enable-loop-distribute -S \ +; RUN: < %s | FileCheck %s +; ModuleID = '' +target datalayout = "e-m:e-p270:32:32-p271:32:32-p272:64:64-i64:64-f80:128-n8:16:32:64-S128" +target triple = "x86_64-unknown-linux-gnu" + +define void @reduced(i32* %0, i32* %1, i64 %indvars.iv, i32* %2, i64 %indvars.iv76, i64 %indvars.iv93) { +;CHECK-LABEL: @reduced( +entry: + br label %for.body + +for.body: ; preds = %for.body, %entry + %indvars.iv761 = phi i64 [ 0, %entry ], [ %indvars.iv.next77, %for.body ] + %indvars.iv4 = phi i64 [ 0, %entry ], [ %indvars.iv.next, %for.body ] + %indvars.iv.next77 = add i64 %indvars.iv761, 1 + %arrayidx.i.i50 = getelementptr i32, i32* %0, i64 %indvars.iv76 + %indvars.iv.next = add i64 %indvars.iv4, 1 + %exitcond.not = icmp eq i64 %indvars.iv4, %indvars.iv + br i1 %exitcond.not, label %for.body13.preheader, label %for.body + +for.body13.preheader: ; preds = %for.body + br label %for.body13 + +for.body26.lr.ph: ; preds = %for.body13 + %idxprom.i.i61 = and i64 %indvars.iv761, 1 + %arrayidx.i.i62 = getelementptr i32, i32* %0, i64 %idxprom.i.i61 + br label %for.body26 + +for.body13: ; preds = %for.body13, %for.body13.preheader + %indvars.iv846 = phi i64 [ %indvars.iv.next85, %for.body13 ], [ 0, %for.body13.preheader ] + %indvars.iv.next87 = add i64 0, 0 + %arrayidx.i.i56 = getelementptr i32, i32* %0, i64 %indvars.iv761 + %3 = load i32, i32* %arrayidx.i.i56, align 4 + store i32 0, i32* %1, align 4 + %indvars.iv.next85 = add i64 %indvars.iv846, 1 + %exitcond92.not = icmp eq i64 %indvars.iv846, %indvars.iv + br i1 %exitcond92.not, label %for.body26.lr.ph, label %for.body13 + +for.cond.cleanup25: ; preds = %for.body26 + ret void + +for.body26: ; preds = %for.body26, %for.body26.lr.ph + %indvars.iv932 = phi i64 [ 0, %for.body26.lr.ph ], [ %indvars.iv.next94, %for.body26 ] + %4 = load i32, i32* %arrayidx.i.i62, align 4 + %arrayidx.i.i653 = getelementptr i32, i32* %2, i64 %indvars.iv93 + store i32 0, i32* %1, align 4 + %indvars.iv.next94 = add i64 %indvars.iv932, 1 + %exitcond97.not = icmp eq i64 %indvars.iv932, %indvars.iv + br i1 %exitcond97.not, label %for.cond.cleanup25, label %for.body26 +}