[PATCH] D64101: [LoopUnroll] fix cloning callbr
Nick Desaulniers via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Tue Jul 2 18:19:03 PDT 2019
nickdesaulniers updated this revision to Diff 207685.
nickdesaulniers added a comment.
- reroll loops, prefer conciseness
Repository:
rG LLVM Github Monorepo
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D64101/new/
https://reviews.llvm.org/D64101
Files:
llvm/lib/Transforms/Utils/LoopUnroll.cpp
llvm/test/Transforms/LoopUnroll/callbr.ll
Index: llvm/test/Transforms/LoopUnroll/callbr.ll
===================================================================
--- /dev/null
+++ llvm/test/Transforms/LoopUnroll/callbr.ll
@@ -0,0 +1,47 @@
+; RUN: opt -loop-unroll -S -o - %s 2>&1 | FileCheck %s
+
+; CHECK-LABEL: if.then:
+; CHECK-NEXT: callbr void asm sideeffect "1: nop\0A\09.quad b, ${0:l}, $$5\0A\09", "X,~{dirflag},~{fpsr},~{flags}"(i8* blockaddress(@d, %l_yes))
+; CHECK-NEXT: to label %asm.fallthrough [label %l_yes]
+; CHECK-LABEL: l_yes:
+
+; CHECK-LABEL: if.then.1:
+; CHECK-NEXT: callbr void asm sideeffect "1: nop\0A\09.quad b, ${0:l}, $$5\0A\09", "X,~{dirflag},~{fpsr},~{flags}"(i8* blockaddress(@d, %l_yes.1))
+; CHECK-NEXT: to label %asm.fallthrough.1 [label %l_yes.1]
+; CHECK-LABLE: l_yes.1:
+
+; CHECK-LABEL: if.then.2:
+; CHECK-NEXT: callbr void asm sideeffect "1: nop\0A\09.quad b, ${0:l}, $$5\0A\09", "X,~{dirflag},~{fpsr},~{flags}"(i8* blockaddress(@d, %l_yes.2))
+; CHECK-NEXT: to label %asm.fallthrough.2 [label %l_yes.2]
+; CHECK-LABEL: l_yes.2:
+
+define dso_local i32 @d() {
+entry:
+ br label %for.body
+
+for.cond.cleanup: ; preds = %for.inc
+ ret i32 undef
+
+for.body: ; preds = %for.inc, %entry
+ %e.04 = phi i32 [ 0, %entry ], [ %inc, %for.inc ]
+ %tobool = icmp eq i32 %e.04, 0
+ br i1 %tobool, label %for.inc, label %if.then
+
+if.then: ; preds = %for.body
+ callbr void asm sideeffect "1: nop\0A\09.quad b, ${0:l}, $$5\0A\09", "X,~{dirflag},~{fpsr},~{flags}"(i8* blockaddress(@d, %l_yes))
+ to label %asm.fallthrough [label %l_yes]
+
+asm.fallthrough: ; preds = %if.then
+ br label %l_yes
+
+l_yes: ; preds = %asm.fallthrough, %if.then
+ %call = tail call i32 (...) @g()
+ br label %for.inc
+
+for.inc: ; preds = %for.body, %l_yes
+ %inc = add nuw nsw i32 %e.04, 1
+ %exitcond = icmp eq i32 %inc, 3
+ br i1 %exitcond, label %for.cond.cleanup, label %for.body
+}
+
+declare dso_local i32 @g(...) local_unnamed_addr
Index: llvm/lib/Transforms/Utils/LoopUnroll.cpp
===================================================================
--- llvm/lib/Transforms/Utils/LoopUnroll.cpp
+++ llvm/lib/Transforms/Utils/LoopUnroll.cpp
@@ -65,8 +65,8 @@
/// Convert the instruction operands from referencing the current values into
/// those specified by VMap.
void llvm::remapInstruction(Instruction *I, ValueToValueMapTy &VMap) {
- for (unsigned op = 0, E = I->getNumOperands(); op != E; ++op) {
- Value *Op = I->getOperand(op);
+ for (unsigned OpNo = 0, E = I->getNumOperands(); OpNo != E; ++OpNo) {
+ Value *Op = I->getOperand(OpNo);
// Unwrap arguments of dbg.value intrinsics.
bool Wrapped = false;
@@ -83,7 +83,14 @@
ValueToValueMapTy::iterator It = VMap.find(Op);
if (It != VMap.end())
- I->setOperand(op, wrap(It->second));
+ I->setOperand(OpNo, wrap(It->second));
+
+ if (auto *BA = dyn_cast<BlockAddress>(Op)) {
+ ValueToValueMapTy::iterator It = VMap.find(BA->getBasicBlock());
+ if (It != VMap.end() && isa<CallBrInst>(*I))
+ if (auto *NewBB = dyn_cast<BasicBlock>(It->second))
+ I->setOperand(OpNo, BlockAddress::get(NewBB));
+ }
}
if (PHINode *PN = dyn_cast<PHINode>(I)) {
@@ -537,7 +544,6 @@
// For the first iteration of the loop, we should use the precloned values for
// PHI nodes. Insert associations now.
- ValueToValueMapTy LastValueMap;
std::vector<PHINode*> OrigPHINode;
for (BasicBlock::iterator I = Header->begin(); isa<PHINode>(I); ++I) {
OrigPHINode.push_back(cast<PHINode>(I));
@@ -594,6 +600,7 @@
<< DIL->getFilename() << " Line: " << DIL->getLine());
}
+ ValueToValueMapTy LastValueMap;
for (unsigned It = 1; It != ULO.Count; ++It) {
std::vector<BasicBlock*> NewBlocks;
SmallDenseMap<const Loop *, Loop *, 4> NewLoops;
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D64101.207685.patch
Type: text/x-patch
Size: 4035 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20190703/c534501a/attachment.bin>
More information about the llvm-commits
mailing list