[llvm] r237395 - Add another InstCombine pass after LoopUnroll.
Wei Mi
wmi at google.com
Thu May 14 15:02:54 PDT 2015
Author: wmi
Date: Thu May 14 17:02:54 2015
New Revision: 237395
URL: http://llvm.org/viewvc/llvm-project?rev=237395&view=rev
Log:
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
Added:
llvm/trunk/test/Transforms/LoopUnroll/unroll-cleanup.ll
Modified:
llvm/trunk/lib/Transforms/IPO/PassManagerBuilder.cpp
Modified: llvm/trunk/lib/Transforms/IPO/PassManagerBuilder.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Transforms/IPO/PassManagerBuilder.cpp?rev=237395&r1=237394&r2=237395&view=diff
==============================================================================
--- llvm/trunk/lib/Transforms/IPO/PassManagerBuilder.cpp (original)
+++ llvm/trunk/lib/Transforms/IPO/PassManagerBuilder.cpp Thu May 14 17:02:54 2015
@@ -382,6 +382,9 @@ void PassManagerBuilder::populateModuleP
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());
Added: llvm/trunk/test/Transforms/LoopUnroll/unroll-cleanup.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Transforms/LoopUnroll/unroll-cleanup.ll?rev=237395&view=auto
==============================================================================
--- llvm/trunk/test/Transforms/LoopUnroll/unroll-cleanup.ll (added)
+++ llvm/trunk/test/Transforms/LoopUnroll/unroll-cleanup.ll Thu May 14 17:02:54 2015
@@ -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 = '<stdin>'
+target triple = "x86_64-unknown-linux-gnu"
+
+ at b = global i32 0, align 4
+ at 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}
More information about the llvm-commits
mailing list