From: Wei Mi Date: Thu, 14 May 2015 22:02:54 +0000 (+0000) Subject: Add another InstCombine pass after LoopUnroll. X-Git-Url: http://demsky.eecs.uci.edu/git/?a=commitdiff_plain;h=95f7517f1bf0bc4d9dc29a8d07df8395d8abc906;p=oota-llvm.git Add another InstCombine pass after LoopUnroll. This is to cleanup some redundency generated by LoopUnroll pass. Such redundency may not be cleaned up by existing passes after LoopUnroll. Differential Revision: http://reviews.llvm.org/D9777 git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@237395 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/lib/Transforms/IPO/PassManagerBuilder.cpp b/lib/Transforms/IPO/PassManagerBuilder.cpp index 94d419fc7f3..3b21d3f0cb1 100644 --- a/lib/Transforms/IPO/PassManagerBuilder.cpp +++ b/lib/Transforms/IPO/PassManagerBuilder.cpp @@ -382,6 +382,9 @@ void PassManagerBuilder::populateModulePassManager( if (!DisableUnrollLoops) { MPM.add(createLoopUnrollPass()); // Unroll small loops + // LoopUnroll may generate some redundency to cleanup. + MPM.add(createInstructionCombiningPass()); + // This is a barrier pass to avoid combine LICM pass and loop unroll pass // within same loop pass manager. MPM.add(createInstructionSimplifierPass()); diff --git a/test/Transforms/LoopUnroll/unroll-cleanup.ll b/test/Transforms/LoopUnroll/unroll-cleanup.ll new file mode 100644 index 00000000000..1e42203876e --- /dev/null +++ b/test/Transforms/LoopUnroll/unroll-cleanup.ll @@ -0,0 +1,85 @@ +; PR23524 +; The test is to check redundency produced by loop unroll pass +; should be cleaned up by later pass. +; RUN: opt < %s -O2 -S | FileCheck %s + +; After loop unroll: +; %dec18 = add nsw i32 %dec18.in, -1 +; ... +; %dec18.1 = add nsw i32 %dec18, -1 +; should be merged to: +; %dec18.1 = add nsw i32 %dec18.in, -2 +; +; CHECK-LABEL: @_Z3fn1v( +; CHECK: %dec18.1 = add nsw i32 %dec18.in, -2 + +; ModuleID = '' +target triple = "x86_64-unknown-linux-gnu" + +@b = global i32 0, align 4 +@c = global i32 0, align 4 + +; Function Attrs: nounwind uwtable +define void @_Z3fn1v() #0 { +entry: + %tmp = load i32, i32* @b, align 4 + %tobool20 = icmp eq i32 %tmp, 0 + br i1 %tobool20, label %for.end6, label %for.body.lr.ph + +for.body.lr.ph: ; preds = %entry + br label %for.body + +for.cond1.for.cond.loopexit_crit_edge: ; preds = %for.inc + %add.ptr.lcssa = phi i16* [ %add.ptr, %for.inc ] + %incdec.ptr.lcssa = phi i8* [ %incdec.ptr, %for.inc ] + br label %for.cond.loopexit + +for.cond.loopexit: ; preds = %for.body, %for.cond1.for.cond.loopexit_crit_edge + %r.1.lcssa = phi i16* [ %add.ptr.lcssa, %for.cond1.for.cond.loopexit_crit_edge ], [ %r.022, %for.body ] + %a.1.lcssa = phi i8* [ %incdec.ptr.lcssa, %for.cond1.for.cond.loopexit_crit_edge ], [ %a.021, %for.body ] + %tmp1 = load i32, i32* @b, align 4 + %tobool = icmp eq i32 %tmp1, 0 + br i1 %tobool, label %for.cond.for.end6_crit_edge, label %for.body + +for.body: ; preds = %for.cond.loopexit, %for.body.lr.ph + %r.022 = phi i16* [ undef, %for.body.lr.ph ], [ %r.1.lcssa, %for.cond.loopexit ] + %a.021 = phi i8* [ undef, %for.body.lr.ph ], [ %a.1.lcssa, %for.cond.loopexit ] + %tmp2 = load i32, i32* @c, align 4 + %tobool215 = icmp eq i32 %tmp2, 0 + br i1 %tobool215, label %for.cond.loopexit, label %for.body3.lr.ph + +for.body3.lr.ph: ; preds = %for.body + br label %for.body3 + +for.body3: ; preds = %for.inc, %for.body3.lr.ph + %dec18.in = phi i32 [ %tmp2, %for.body3.lr.ph ], [ %dec18, %for.inc ] + %r.117 = phi i16* [ %r.022, %for.body3.lr.ph ], [ %add.ptr, %for.inc ] + %a.116 = phi i8* [ %a.021, %for.body3.lr.ph ], [ %incdec.ptr, %for.inc ] + %dec18 = add nsw i32 %dec18.in, -1 + %tmp3 = load i8, i8* %a.116, align 1 + %cmp = icmp eq i8 %tmp3, 0 + br i1 %cmp, label %if.then, label %for.inc + +if.then: ; preds = %for.body3 + %arrayidx = getelementptr inbounds i16, i16* %r.117, i64 1 + store i16 0, i16* %arrayidx, align 2 + store i16 0, i16* %r.117, align 2 + %arrayidx5 = getelementptr inbounds i16, i16* %r.117, i64 2 + store i16 0, i16* %arrayidx5, align 2 + br label %for.inc + +for.inc: ; preds = %if.then, %for.body3 + %incdec.ptr = getelementptr inbounds i8, i8* %a.116, i64 1 + %add.ptr = getelementptr inbounds i16, i16* %r.117, i64 3 + %tobool2 = icmp eq i32 %dec18, 0 + br i1 %tobool2, label %for.cond1.for.cond.loopexit_crit_edge, label %for.body3, !llvm.loop !0 + +for.cond.for.end6_crit_edge: ; preds = %for.cond.loopexit + br label %for.end6 + +for.end6: ; preds = %for.cond.for.end6_crit_edge, %entry + ret void +} + +!0 = !{!0, !1} +!1 = !{!"llvm.loop.unroll.count", i32 2}