[PATCH] D74747: [JumpThreading] Handle unconditional PredBB when threading jumps through two basic blocks
Fangrui Song via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Tue Feb 18 09:12:32 PST 2020
MaskRay updated this revision to Diff 245184.
MaskRay marked an inline comment as done.
MaskRay added a comment.
Delete dso_local
Repository:
rG LLVM Github Monorepo
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D74747/new/
https://reviews.llvm.org/D74747
Files:
llvm/lib/Transforms/Scalar/JumpThreading.cpp
llvm/test/Transforms/JumpThreading/thread-two-bbs6.ll
Index: llvm/test/Transforms/JumpThreading/thread-two-bbs6.ll
===================================================================
--- /dev/null
+++ llvm/test/Transforms/JumpThreading/thread-two-bbs6.ll
@@ -0,0 +1,46 @@
+;; Test that we can handle unconditional PredBB when threading jumps through two
+;; successive basic blocks.
+; RUN: opt -S -passes='function(jump-threading)' < %s | FileCheck %s
+
+target datalayout = "e-m:e-p270:32:32-p271:32:32-p272:64:64-i64:64-f80:128-n8:16:32:64-S128"
+target triple = "x86_64-unknown-linux-gnu"
+
+define i32 @f(i32* %0) {
+; CHECK-LABEL: @f
+; CHECK: br i1 %good, label %bb, label %cont1.thread
+entry:
+ %size = call i64 @get_size(i32* %0)
+ %good = icmp ugt i64 %size, 3
+ br i1 %good, label %bb, label %pred.bb
+
+; CHECK: bb:
+; CHECK-NEXT: %v = load i32, i32* %0
+; CHECK-NEXT: br label %cont1
+; CHECK: cont1.thread:
+; CHECK: call void @effect()
+; CHECK-NEXT: %v1 = load i32, i32* %0
+; CHECK-NEXT: call void @effect1(i8* blockaddress(@f, %cont1))
+; CHECK: cont1:
+; CHECK: call void @effect1(i8* blockaddress(@f, %cont1))
+pred.bb: ; preds = %entry
+ call void @effect()
+ br label %bb
+bb: ; preds = %pred.bb, %entry
+ %v = load i32, i32* %0
+ br label %cont1
+
+cont1: ; preds = %bb
+ call void @effect1(i8* blockaddress(@f, %cont1))
+ br i1 %good, label %cont3, label %cont2
+
+cont2: ; preds = %cont1
+ br i1 %good, label %exit, label %cont3
+cont3: ; preds = %cont2
+ br label %exit
+exit: ; preds = %cont3, %cont2
+ ret i32 %v
+}
+
+declare i64 @get_size(i32*)
+declare void @effect()
+declare void @effect1(i8*)
Index: llvm/lib/Transforms/Scalar/JumpThreading.cpp
===================================================================
--- llvm/lib/Transforms/Scalar/JumpThreading.cpp
+++ llvm/lib/Transforms/Scalar/JumpThreading.cpp
@@ -2250,8 +2250,9 @@
AddPHINodeEntriesForMappedBlock(PredBBBranch->getSuccessor(0), PredBB, NewBB,
ValueMapping);
- AddPHINodeEntriesForMappedBlock(PredBBBranch->getSuccessor(1), PredBB, NewBB,
- ValueMapping);
+ if (PredBBBranch->isConditional())
+ AddPHINodeEntriesForMappedBlock(PredBBBranch->getSuccessor(1), PredBB,
+ NewBB, ValueMapping);
DTU->applyUpdatesPermissive(
{{DominatorTree::Insert, NewBB, CondBr->getSuccessor(0)},
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D74747.245184.patch
Type: text/x-patch
Size: 2671 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20200218/6bf144a8/attachment.bin>
More information about the llvm-commits
mailing list