[llvm] 20962c1 - [SimplifyCFG] Don't split predecessors of callbr terminator

Nikita Popov via llvm-commits llvm-commits at lists.llvm.org
Wed Jul 6 06:39:02 PDT 2022


Author: Nikita Popov
Date: 2022-07-06T15:38:53+02:00
New Revision: 20962c1240691d25b21ce425313c81eed0b1b358

URL: https://github.com/llvm/llvm-project/commit/20962c1240691d25b21ce425313c81eed0b1b358
DIFF: https://github.com/llvm/llvm-project/commit/20962c1240691d25b21ce425313c81eed0b1b358.diff

LOG: [SimplifyCFG] Don't split predecessors of callbr terminator

This addresses the assertion failure reported in
https://reviews.llvm.org/D124159#3631240.

I believe that this limitation in SplitBlockPredecessors is not
actually necessary (because unlike with indirectbr, callbr is
restricted in a way that does allow updating successors), but for
now fix the assertion failure the same way we do everywhere else,
by also skipping callbr.

Added: 
    

Modified: 
    llvm/lib/Transforms/Utils/SimplifyCFG.cpp
    llvm/test/Transforms/SimplifyCFG/jump-threading.ll

Removed: 
    


################################################################################
diff  --git a/llvm/lib/Transforms/Utils/SimplifyCFG.cpp b/llvm/lib/Transforms/Utils/SimplifyCFG.cpp
index 86b2128a1937..7d76a6b68d0a 100644
--- a/llvm/lib/Transforms/Utils/SimplifyCFG.cpp
+++ b/llvm/lib/Transforms/Utils/SimplifyCFG.cpp
@@ -3033,7 +3033,8 @@ FoldCondBranchOnValueKnownInPredecessorImpl(BranchInst *BI, DomTreeUpdater *DTU,
 
     // Skip if the predecessor's terminator is an indirect branch.
     if (any_of(PredBBs, [](BasicBlock *PredBB) {
-          return isa<IndirectBrInst>(PredBB->getTerminator());
+          return isa<IndirectBrInst>(PredBB->getTerminator()) ||
+                 isa<CallBrInst>(PredBB->getTerminator());
         }))
       continue;
 

diff  --git a/llvm/test/Transforms/SimplifyCFG/jump-threading.ll b/llvm/test/Transforms/SimplifyCFG/jump-threading.ll
index 4f99e55b15a3..113ea6a01423 100644
--- a/llvm/test/Transforms/SimplifyCFG/jump-threading.ll
+++ b/llvm/test/Transforms/SimplifyCFG/jump-threading.ll
@@ -420,3 +420,38 @@ loop.latch:
 exit:
   ret void
 }
+
+define void @callbr() {
+; CHECK-LABEL: @callbr(
+; CHECK-NEXT:  entry:
+; CHECK-NEXT:    callbr void asm sideeffect "", "i,~{dirflag},~{fpsr},~{flags}"(ptr blockaddress(@callbr, [[TARGET:%.*]]))
+; CHECK-NEXT:    to label [[JOIN:%.*]] [label %target]
+; CHECK:       target:
+; CHECK-NEXT:    br label [[JOIN]]
+; CHECK:       join:
+; CHECK-NEXT:    [[PHI:%.*]] = phi i1 [ false, [[TARGET]] ], [ false, [[ENTRY:%.*]] ]
+; CHECK-NEXT:    br i1 [[PHI]], label [[IF_THEN:%.*]], label [[IF_END:%.*]]
+; CHECK:       if.then:
+; CHECK-NEXT:    call void @foo()
+; CHECK-NEXT:    br label [[IF_END]]
+; CHECK:       if.end:
+; CHECK-NEXT:    ret void
+;
+entry:
+  callbr void asm sideeffect "", "i,~{dirflag},~{fpsr},~{flags}"(ptr blockaddress(@callbr, %target))
+  to label %join [label %target]
+
+target:
+  br label %join
+
+join:
+  %phi = phi i1 [ false, %target ], [ false, %entry ]
+  br i1 %phi, label %if.then, label %if.end
+
+if.then:
+  call void @foo()
+  br label %if.end
+
+if.end:
+  ret void
+}


        


More information about the llvm-commits mailing list