[PATCH] D127765: modify the insertion of freeze instructions for SLU pass
Ruobing Han via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Tue Jun 14 10:35:48 PDT 2022
drcut updated this revision to Diff 436850.
drcut added a comment.
Fix bug for hoisting freeze instruction
Repository:
rG LLVM Github Monorepo
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D127765/new/
https://reviews.llvm.org/D127765
Files:
llvm/lib/Transforms/Scalar/SimpleLoopUnswitch.cpp
llvm/test/Transforms/SimpleLoopUnswitch/exponential-nontrivial-unswitch-nested.ll
llvm/test/Transforms/SimpleLoopUnswitch/nontrivial-unswitch.ll
Index: llvm/test/Transforms/SimpleLoopUnswitch/nontrivial-unswitch.ll
===================================================================
--- llvm/test/Transforms/SimpleLoopUnswitch/nontrivial-unswitch.ll
+++ llvm/test/Transforms/SimpleLoopUnswitch/nontrivial-unswitch.ll
@@ -2437,8 +2437,9 @@
br label %bb3
; CHECK-NOT: br i1 %a
;
-; CHECK: %[[FROZEN:.+]] = freeze i1 %a
-; CHECK-NEXT: br i1 %[[FROZEN]], label %[[BB_SPLIT_US:.*]], label %[[BB_SPLIT:.*]]
+; CHECK: %[[FROZENA:.+]] = freeze i1 %a
+; CHECK: %[[FROZENB:.+]] = freeze i1 %b
+; CHECK-NEXT: br i1 %[[FROZENA]], label %[[BB_SPLIT_US:.*]], label %[[BB_SPLIT:.*]]
;
; CHECK-NOT: br i1 %a
; CHECK-NOT: br i1 %b
Index: llvm/test/Transforms/SimpleLoopUnswitch/exponential-nontrivial-unswitch-nested.ll
===================================================================
--- llvm/test/Transforms/SimpleLoopUnswitch/exponential-nontrivial-unswitch-nested.ll
+++ llvm/test/Transforms/SimpleLoopUnswitch/exponential-nontrivial-unswitch-nested.ll
@@ -35,6 +35,11 @@
; RUN: -passes='loop-mssa(licm,simple-loop-unswitch<nontrivial>),print<loops>' -disable-output 2>&1 | \
; RUN: sort -b -k 1 | FileCheck %s --check-prefixes=LOOP-UNSCALE4-DIV1
;
+; RUN: opt < %s -enable-unswitch-cost-multiplier=true \
+; RUN: -unswitch-num-initial-unscaled-candidates=4 -unswitch-siblings-toplevel-div=1 \
+; RUN: -passes='loop-unswitch-func,print<loops>' -disable-output 2>&1 | \
+; RUN: sort -b -k 1 | FileCheck %s --check-prefixes=LOOP-UNSCALE4-DIV1
+;
; NB: sort -b is essential here and below, otherwise blanks might lead to different
; order depending on locale.
;
@@ -43,6 +48,11 @@
; RUN: -passes='loop-mssa(licm,simple-loop-unswitch<nontrivial>),print<loops>' -disable-output 2>&1 | \
; RUN: sort -b -k 1 | FileCheck %s --check-prefixes=LOOP-UNSCALE4-DIV2
;
+; RUN: opt < %s -enable-unswitch-cost-multiplier=true \
+; RUN: -unswitch-num-initial-unscaled-candidates=4 -unswitch-siblings-toplevel-div=2 \
+; RUN: -passes='loop-unswitch-func,print<loops>' -disable-output 2>&1 | \
+; RUN: sort -b -k 1 | FileCheck %s --check-prefixes=LOOP-UNSCALE4-DIV2
+;
; Get
; 2^(num conds) == 2^5 = 32
; loop nests when cost multiplier is disabled:
@@ -51,6 +61,10 @@
; RUN: -passes='loop-mssa(licm,simple-loop-unswitch<nontrivial>),print<loops>' -disable-output 2>&1 | \
; RUN: sort -b -k 1 | FileCheck %s --check-prefixes=LOOP32
;
+; RUN: opt < %s -enable-unswitch-cost-multiplier=false \
+; RUN: -passes='loop-unswitch-func,print<loops>' -disable-output 2>&1 | \
+; RUN: sort -b -k 1 | FileCheck %s --check-prefixes=LOOP32
+;
; Single loop nest, not unswitched
; LOOP1: Loop at depth 1 containing:
; LOOP1: Loop at depth 2 containing:
Index: llvm/lib/Transforms/Scalar/SimpleLoopUnswitch.cpp
===================================================================
--- llvm/lib/Transforms/Scalar/SimpleLoopUnswitch.cpp
+++ llvm/lib/Transforms/Scalar/SimpleLoopUnswitch.cpp
@@ -2238,8 +2238,19 @@
BI->setSuccessor(1 - ClonedSucc, LoopPH);
Value *Cond = skipTrivialSelect(BI->getCondition());
if (InsertFreeze) {
- if (!isGuaranteedNotToBeUndefOrPoison(Cond, &AC, BI, &DT))
- Cond = new FreezeInst(Cond, Cond->getName() + ".fr", BI);
+ if (!isGuaranteedNotToBeUndefOrPoison(Cond, &AC, BI, &DT)) {
+ // directly insert the freeze inst to the place it will be hoisted by
+ // LICM, so that we do not require LICM as a following pass
+ Instruction *InsertPoint = BI;
+ while (Loop *OuterLoop = LI.getLoopFor(InsertPoint->getParent())) {
+ if (OuterLoop->isLoopInvariant(Cond)) {
+ InsertPoint = OuterLoop->getLoopPreheader()->getTerminator();
+ } else {
+ break;
+ }
+ }
+ Cond = new FreezeInst(Cond, Cond->getName() + ".fr", InsertPoint);
+ }
}
BI->setCondition(Cond);
DTUpdates.push_back({DominatorTree::Insert, SplitBB, ClonedPH});
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D127765.436850.patch
Type: text/x-patch
Size: 4073 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20220614/d65eb014/attachment.bin>
More information about the llvm-commits
mailing list