[PATCH] D108204: [GVN] Execute performLoopLoadPRE ahead of PerformLoadPRE
JinGu Kang via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Tue Aug 17 06:05:31 PDT 2021
jaykang10 created this revision.
jaykang10 added reviewers: mkazantsev, fhahn, xbolva00, dmgreen, sanwou01.
Herald added a subscriber: hiraditya.
jaykang10 requested review of this revision.
Herald added a project: LLVM.
Herald added a subscriber: llvm-commits.
There are cfgs which both of loop load pre and load pre can handle.
In this case, it could be better to perform loop load pre first because it can reduce the number of execution of load or it can help sccp pass propagate constant.
It fixes https://bugs.llvm.org/show_bug.cgi?id=51141
https://reviews.llvm.org/D108204
Files:
llvm/lib/Transforms/Scalar/GVN.cpp
llvm/test/Transforms/GVN/gvn-loop-load-pre-order.ll
Index: llvm/test/Transforms/GVN/gvn-loop-load-pre-order.ll
===================================================================
--- /dev/null
+++ llvm/test/Transforms/GVN/gvn-loop-load-pre-order.ll
@@ -0,0 +1,65 @@
+; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
+; RUN: opt < %s -loops -gvn -S | FileCheck -check-prefix=CHECK-PRE %s
+; RUN: opt < %s -loops -gvn -sccp -S | FileCheck -check-prefix=CHECK-SCCP %s
+
+ at b = external global i32, align 4
+
+define void @main(i1 %cond) {
+; CHECK-PRE-LABEL: @main(
+; CHECK-PRE-NEXT: entry:
+; CHECK-PRE-NEXT: store i32 0, i32* @b, align 4
+; CHECK-PRE-NEXT: br label [[WHILE_BODY3:%.*]]
+; CHECK-PRE: while.cond.loopexit.loopexit:
+; CHECK-PRE-NEXT: ret void
+; CHECK-PRE: while.body3:
+; CHECK-PRE-NEXT: [[TMP0:%.*]] = phi i32 [ [[TMP1:%.*]], [[IF_END:%.*]] ], [ 0, [[ENTRY:%.*]] ]
+; CHECK-PRE-NEXT: [[TOBOOL4_NOT:%.*]] = icmp eq i32 [[TMP0]], 0
+; CHECK-PRE-NEXT: br i1 [[TOBOOL4_NOT]], label [[IF_END]], label [[IF_THEN:%.*]]
+; CHECK-PRE: if.then:
+; CHECK-PRE-NEXT: tail call void @foo()
+; CHECK-PRE-NEXT: [[DOTPRE:%.*]] = load i32, i32* @b, align 4
+; CHECK-PRE-NEXT: br label [[IF_END]]
+; CHECK-PRE: if.end:
+; CHECK-PRE-NEXT: [[TMP1]] = phi i32 [ [[DOTPRE]], [[IF_THEN]] ], [ 0, [[WHILE_BODY3]] ]
+; CHECK-PRE-NEXT: br i1 [[COND:%.*]], label [[WHILE_COND_LOOPEXIT_LOOPEXIT:%.*]], label [[WHILE_BODY3]]
+;
+; CHECK-SCCP-LABEL: @main(
+; CHECK-SCCP-NEXT: entry:
+; CHECK-SCCP-NEXT: store i32 0, i32* @b, align 4
+; CHECK-SCCP-NEXT: br label [[WHILE_BODY3:%.*]]
+; CHECK-SCCP: while.cond.loopexit.loopexit:
+; CHECK-SCCP-NEXT: ret void
+; CHECK-SCCP: while.body3:
+; CHECK-SCCP-NEXT: br i1 true, label [[IF_END:%.*]], label [[IF_THEN:%.*]]
+; CHECK-SCCP: if.then:
+; CHECK-SCCP-NEXT: br label [[IF_END]]
+; CHECK-SCCP: if.end:
+; CHECK-SCCP-NEXT: br i1 [[COND:%.*]], label [[WHILE_COND_LOOPEXIT_LOOPEXIT:%.*]], label [[WHILE_BODY3]]
+;
+entry:
+ store i32 0, i32* @b
+ br label %while.body3.lr.ph
+
+while.cond.loopexit.loopexit: ; preds = %if.end
+ ret void
+
+while.body3.lr.ph: ; preds = %while.cond1.preheader
+ %0 = load i32, i32* @b, align 4
+ %1 = icmp eq i32 %0, 0
+ br label %while.body3
+
+while.body3: ; preds = %if.end, %while.body3.lr.ph
+ %2 = load i32, i32* @b, align 4
+ %tobool4.not = icmp eq i32 %2, 0
+ br i1 %tobool4.not, label %if.end, label %if.then
+
+if.then: ; preds = %while.body3
+ tail call void @foo()
+ br label %if.end
+
+if.end: ; preds = %if.then, %while.body3
+ br i1 %cond, label %while.cond.loopexit.loopexit, label %while.body3
+}
+
+declare void @foo()
+
Index: llvm/lib/Transforms/Scalar/GVN.cpp
===================================================================
--- llvm/lib/Transforms/Scalar/GVN.cpp
+++ llvm/lib/Transforms/Scalar/GVN.cpp
@@ -1673,8 +1673,9 @@
if (!isLoadInLoopPREEnabled() && LI && LI->getLoopFor(Load->getParent()))
return Changed;
- return Changed || PerformLoadPRE(Load, ValuesPerBlock, UnavailableBlocks) ||
- performLoopLoadPRE(Load, ValuesPerBlock, UnavailableBlocks);
+ return Changed ||
+ performLoopLoadPRE(Load, ValuesPerBlock, UnavailableBlocks) ||
+ PerformLoadPRE(Load, ValuesPerBlock, UnavailableBlocks);
}
static bool impliesEquivalanceIfTrue(CmpInst* Cmp) {
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D108204.366871.patch
Type: text/x-patch
Size: 3537 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20210817/4d3c057d/attachment.bin>
More information about the llvm-commits
mailing list