diff --git a/llvm/lib/Transforms/Scalar/LoopFuse.cpp b/llvm/lib/Transforms/Scalar/LoopFuse.cpp --- a/llvm/lib/Transforms/Scalar/LoopFuse.cpp +++ b/llvm/lib/Transforms/Scalar/LoopFuse.cpp @@ -67,6 +67,7 @@ #include "llvm/Transforms/Utils/BasicBlockUtils.h" #include "llvm/Transforms/Utils/CodeMoverUtils.h" #include "llvm/Transforms/Utils/LoopPeel.h" +#include "llvm/Transforms/Utils/LoopSimplify.h" using namespace llvm; @@ -593,6 +594,13 @@ }); } #endif + for (Loop *L : LV) { + if (!L->isLoopSimplifyForm()) + Changed |= simplifyLoop(L, &DT, <, &SE, &AC, nullptr, + /*PreserveLCSSA=*/false); + } + if (Changed) + PDT.recalculate(F); collectFusionCandidates(LV); Changed |= fuseCandidates(); diff --git a/llvm/test/Transforms/LoopFusion/ensure_loop_simplify_form.ll b/llvm/test/Transforms/LoopFusion/ensure_loop_simplify_form.ll new file mode 100644 --- /dev/null +++ b/llvm/test/Transforms/LoopFusion/ensure_loop_simplify_form.ll @@ -0,0 +1,19 @@ +; RUN: opt -enable-new-pm=1 -loop-fusion < %s + +define dso_local void @v_5_0() { +entry: + br label %for.body + +for.cond.cleanup: ; preds = %for.body + br i1 undef, label %for.body6, label %for.cond.cleanup5 + +for.body: ; preds = %for.body, %entry + br i1 undef, label %for.cond.cleanup, label %for.body + +for.cond.cleanup5: ; preds = %for.cond.cleanup + ret void + +for.body6: ; preds = %for.body6, %for.cond.cleanup + %v_loop_2.0.v_loop_2.0.v_loop_2.0.18 = load volatile i32, i32* undef, align 1 + br label %for.body6 +}