[PATCH] D144927: [GVNHoist] skip hoisting into blocks terminated by callbr

Nick Desaulniers via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Mon Feb 27 15:27:41 PST 2023


nickdesaulniers created this revision.
Herald added a subscriber: hiraditya.
Herald added a project: All.
nickdesaulniers requested review of this revision.
Herald added a project: LLVM.
Herald added a subscriber: llvm-commits.

This isn't safe to do.

Link: https://github.com/llvm/llvm-project/issues/53562
Fixes: https://github.com/llvm/llvm-project/issues/61023


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D144927

Files:
  llvm/lib/Transforms/Scalar/GVNHoist.cpp
  llvm/test/Transforms/GVNHoist/hoist-call.ll


Index: llvm/test/Transforms/GVNHoist/hoist-call.ll
===================================================================
--- llvm/test/Transforms/GVNHoist/hoist-call.ll
+++ llvm/test/Transforms/GVNHoist/hoist-call.ll
@@ -26,3 +26,24 @@
 }
 
 declare float @llvm.fabs.f32(float)
+
+; Check that extractvalues are not hoisted into entry.
+define void @foo() {
+; CHECK-LABEL: define void @foo(
+; CHECK-NEXT: entry
+; CHECK-NEXT: %0 = callbr
+; CHECK-NEXT: to label
+; CHECK-EMPTY:
+; CHECK-NEXT: asm.fallthrough:
+entry:
+  %0 = callbr { i32, i32 } asm sideeffect "somestuff", "=r,=r,!i"()
+          to label %asm.fallthrough [label %err.split]
+
+asm.fallthrough:                                  ; preds = %entry
+  %asmresult = extractvalue { i32, i32 } %0, 0
+  ret void
+
+err.split:                                        ; preds = %entry
+  %asmresult2 = extractvalue { i32, i32 } %0, 0
+  ret void
+}
Index: llvm/lib/Transforms/Scalar/GVNHoist.cpp
===================================================================
--- llvm/lib/Transforms/Scalar/GVNHoist.cpp
+++ llvm/lib/Transforms/Scalar/GVNHoist.cpp
@@ -337,7 +337,8 @@
   // WL to HoistBB.
   bool safeToHoistScalar(const BasicBlock *HoistBB, const BasicBlock *BB,
                          int &NBBsOnAllPaths) {
-    return !hasEHOnPath(HoistBB, BB, NBBsOnAllPaths);
+    return !hasEHOnPath(HoistBB, BB, NBBsOnAllPaths) &&
+           !isa<CallBrInst>(HoistBB->getTerminator());
   }
 
   // In the inverse CFG, the dominance frontier of basic block (BB) is the


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D144927.500939.patch
Type: text/x-patch
Size: 1526 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20230227/39836173/attachment.bin>


More information about the llvm-commits mailing list