[llvm] 82ac399 - [SimplifyCFG] Allow merging invoke's with different attrs
Noah Goldstein via llvm-commits
llvm-commits at lists.llvm.org
Wed Oct 9 23:08:16 PDT 2024
Author: Noah Goldstein
Date: 2024-10-10T01:07:59-05:00
New Revision: 82ac3997334f0a128bc770383c09a5ded53daec1
URL: https://github.com/llvm/llvm-project/commit/82ac3997334f0a128bc770383c09a5ded53daec1
DIFF: https://github.com/llvm/llvm-project/commit/82ac3997334f0a128bc770383c09a5ded53daec1.diff
LOG: [SimplifyCFG] Allow merging invoke's with different attrs
Same logic as other callsites, if the attributes are intersectable, we
merge.
Closes #111713
Added:
Modified:
llvm/lib/Transforms/Utils/SimplifyCFG.cpp
llvm/test/Transforms/SimplifyCFG/X86/merge-compatible-invokes-of-landingpad.ll
Removed:
################################################################################
diff --git a/llvm/lib/Transforms/Utils/SimplifyCFG.cpp b/llvm/lib/Transforms/Utils/SimplifyCFG.cpp
index 18d26aaf460662..566ae2cf1936e9 100644
--- a/llvm/lib/Transforms/Utils/SimplifyCFG.cpp
+++ b/llvm/lib/Transforms/Utils/SimplifyCFG.cpp
@@ -2779,7 +2779,7 @@ bool CompatibleSets::shouldBelongToSameSet(ArrayRef<InvokeInst *> Invokes) {
// including operand bundles.
const InvokeInst *II0 = Invokes.front();
for (auto *II : Invokes.drop_front())
- if (!II->isSameOperationAs(II0))
+ if (!II->isSameOperationAs(II0, Instruction::CompareUsingIntersectedAttrs))
return false;
// Can we theoretically form the data operands for the merged `invoke`?
@@ -2918,6 +2918,10 @@ static void mergeCompatibleInvokesImpl(ArrayRef<InvokeInst *> Invokes,
for (BasicBlock *OrigSuccBB : successors(II->getParent()))
OrigSuccBB->removePredecessor(II->getParent());
BranchInst::Create(MergedInvoke->getParent(), II->getParent());
+ bool Success = MergedInvoke->tryIntersectAttributes(II);
+ assert(Success && "Merged invokes with incompatible attributes");
+ // For NDEBUG Compile
+ (void)Success;
II->replaceAllUsesWith(MergedInvoke);
II->eraseFromParent();
++NumInvokesMerged;
diff --git a/llvm/test/Transforms/SimplifyCFG/X86/merge-compatible-invokes-of-landingpad.ll b/llvm/test/Transforms/SimplifyCFG/X86/merge-compatible-invokes-of-landingpad.ll
index 0b676bd80e185f..95114abb4ef5fe 100644
--- a/llvm/test/Transforms/SimplifyCFG/X86/merge-compatible-invokes-of-landingpad.ll
+++ b/llvm/test/Transforms/SimplifyCFG/X86/merge-compatible-invokes-of-landingpad.ll
@@ -1013,24 +1013,19 @@ define void @t17_mismatched_attrs_okay_merge() personality ptr @__gxx_personalit
; CHECK-LABEL: define void @t17_mismatched_attrs_okay_merge() personality ptr @__gxx_personality_v0 {
; CHECK-NEXT: [[ENTRY:.*:]]
; CHECK-NEXT: [[C0:%.*]] = call i1 @cond()
-; CHECK-NEXT: br i1 [[C0]], label %[[IF_THEN0:.*]], label %[[IF_ELSE:.*]]
-; CHECK: [[IF_THEN0]]:
-; CHECK-NEXT: invoke void @simple_throw() #[[ATTR2:[0-9]+]]
-; CHECK-NEXT: to label %[[INVOKE_CONT0:.*]] unwind label %[[LPAD:.*]]
-; CHECK: [[INVOKE_CONT0]]:
-; CHECK-NEXT: unreachable
-; CHECK: [[LPAD]]:
+; CHECK-NEXT: br i1 [[C0]], label %[[IF_THEN1_INVOKE:.*]], label %[[IF_ELSE:.*]]
+; CHECK: [[LPAD:.*]]:
; CHECK-NEXT: [[EH:%.*]] = landingpad { ptr, i32 }
; CHECK-NEXT: cleanup
; CHECK-NEXT: call void @destructor()
; CHECK-NEXT: resume { ptr, i32 } [[EH]]
; CHECK: [[IF_ELSE]]:
; CHECK-NEXT: [[C1:%.*]] = call i1 @cond()
-; CHECK-NEXT: br i1 [[C1]], label %[[IF_THEN1:.*]], label %[[IF_END:.*]]
-; CHECK: [[IF_THEN1]]:
+; CHECK-NEXT: br i1 [[C1]], label %[[IF_THEN1_INVOKE]], label %[[IF_END:.*]]
+; CHECK: [[IF_THEN1_INVOKE]]:
; CHECK-NEXT: invoke void @simple_throw()
-; CHECK-NEXT: to label %[[INVOKE_CONT2:.*]] unwind label %[[LPAD]]
-; CHECK: [[INVOKE_CONT2]]:
+; CHECK-NEXT: to label %[[IF_THEN1_CONT:.*]] unwind label %[[LPAD]]
+; CHECK: [[IF_THEN1_CONT]]:
; CHECK-NEXT: unreachable
; CHECK: [[IF_END]]:
; CHECK-NEXT: call void @sideeffect()
@@ -1070,24 +1065,19 @@ define void @t17_mismatched_attrs_okay_merge_intersect() personality ptr @__gxx_
; CHECK-LABEL: define void @t17_mismatched_attrs_okay_merge_intersect() personality ptr @__gxx_personality_v0 {
; CHECK-NEXT: [[ENTRY:.*:]]
; CHECK-NEXT: [[C0:%.*]] = call i1 @cond()
-; CHECK-NEXT: br i1 [[C0]], label %[[IF_THEN0:.*]], label %[[IF_ELSE:.*]]
-; CHECK: [[IF_THEN0]]:
-; CHECK-NEXT: invoke void @simple_throw() #[[ATTR3:[0-9]+]]
-; CHECK-NEXT: to label %[[INVOKE_CONT0:.*]] unwind label %[[LPAD:.*]]
-; CHECK: [[INVOKE_CONT0]]:
-; CHECK-NEXT: unreachable
-; CHECK: [[LPAD]]:
+; CHECK-NEXT: br i1 [[C0]], label %[[IF_THEN1_INVOKE:.*]], label %[[IF_ELSE:.*]]
+; CHECK: [[LPAD:.*]]:
; CHECK-NEXT: [[EH:%.*]] = landingpad { ptr, i32 }
; CHECK-NEXT: cleanup
; CHECK-NEXT: call void @destructor()
; CHECK-NEXT: resume { ptr, i32 } [[EH]]
; CHECK: [[IF_ELSE]]:
; CHECK-NEXT: [[C1:%.*]] = call i1 @cond()
-; CHECK-NEXT: br i1 [[C1]], label %[[IF_THEN1:.*]], label %[[IF_END:.*]]
-; CHECK: [[IF_THEN1]]:
-; CHECK-NEXT: invoke void @simple_throw() #[[ATTR2]]
-; CHECK-NEXT: to label %[[INVOKE_CONT2:.*]] unwind label %[[LPAD]]
-; CHECK: [[INVOKE_CONT2]]:
+; CHECK-NEXT: br i1 [[C1]], label %[[IF_THEN1_INVOKE]], label %[[IF_END:.*]]
+; CHECK: [[IF_THEN1_INVOKE]]:
+; CHECK-NEXT: invoke void @simple_throw() #[[ATTR2:[0-9]+]]
+; CHECK-NEXT: to label %[[IF_THEN1_CONT:.*]] unwind label %[[LPAD]]
+; CHECK: [[IF_THEN1_CONT]]:
; CHECK-NEXT: unreachable
; CHECK: [[IF_END]]:
; CHECK-NEXT: call void @sideeffect()
@@ -1127,24 +1117,19 @@ define void @t17_mismatched_attrs_okay_merge_intersect2() personality ptr @__gxx
; CHECK-LABEL: define void @t17_mismatched_attrs_okay_merge_intersect2() personality ptr @__gxx_personality_v0 {
; CHECK-NEXT: [[ENTRY:.*:]]
; CHECK-NEXT: [[C0:%.*]] = call i1 @cond()
-; CHECK-NEXT: br i1 [[C0]], label %[[IF_THEN0:.*]], label %[[IF_ELSE:.*]]
-; CHECK: [[IF_THEN0]]:
-; CHECK-NEXT: invoke void @simple_throw() #[[ATTR2]]
-; CHECK-NEXT: to label %[[INVOKE_CONT0:.*]] unwind label %[[LPAD:.*]]
-; CHECK: [[INVOKE_CONT0]]:
-; CHECK-NEXT: unreachable
-; CHECK: [[LPAD]]:
+; CHECK-NEXT: br i1 [[C0]], label %[[IF_THEN1_INVOKE:.*]], label %[[IF_ELSE:.*]]
+; CHECK: [[LPAD:.*]]:
; CHECK-NEXT: [[EH:%.*]] = landingpad { ptr, i32 }
; CHECK-NEXT: cleanup
; CHECK-NEXT: call void @destructor()
; CHECK-NEXT: resume { ptr, i32 } [[EH]]
; CHECK: [[IF_ELSE]]:
; CHECK-NEXT: [[C1:%.*]] = call i1 @cond()
-; CHECK-NEXT: br i1 [[C1]], label %[[IF_THEN1:.*]], label %[[IF_END:.*]]
-; CHECK: [[IF_THEN1]]:
-; CHECK-NEXT: invoke void @simple_throw() #[[ATTR3]]
-; CHECK-NEXT: to label %[[INVOKE_CONT2:.*]] unwind label %[[LPAD]]
-; CHECK: [[INVOKE_CONT2]]:
+; CHECK-NEXT: br i1 [[C1]], label %[[IF_THEN1_INVOKE]], label %[[IF_END:.*]]
+; CHECK: [[IF_THEN1_INVOKE]]:
+; CHECK-NEXT: invoke void @simple_throw() #[[ATTR2]]
+; CHECK-NEXT: to label %[[IF_THEN1_CONT:.*]] unwind label %[[LPAD]]
+; CHECK: [[IF_THEN1_CONT]]:
; CHECK-NEXT: unreachable
; CHECK: [[IF_END]]:
; CHECK-NEXT: call void @sideeffect()
@@ -1187,7 +1172,7 @@ define void @t17_mismatched_attrs_prevent_merge() personality ptr @__gxx_persona
; CHECK-NEXT: [[C0:%.*]] = call i1 @cond()
; CHECK-NEXT: br i1 [[C0]], label %[[IF_THEN0:.*]], label %[[IF_ELSE:.*]]
; CHECK: [[IF_THEN0]]:
-; CHECK-NEXT: invoke void @simple_throw() #[[ATTR4:[0-9]+]]
+; CHECK-NEXT: invoke void @simple_throw() #[[ATTR3:[0-9]+]]
; CHECK-NEXT: to label %[[INVOKE_CONT0:.*]] unwind label %[[LPAD:.*]]
; CHECK: [[INVOKE_CONT0]]:
; CHECK-NEXT: unreachable
@@ -2693,6 +2678,5 @@ declare dso_local i32 @__gxx_personality_v0(...)
; CHECK: attributes #[[ATTR0:[0-9]+]] = { noreturn }
; CHECK: attributes #[[ATTR1]] = { nomerge }
; CHECK: attributes #[[ATTR2]] = { memory(none) }
-; CHECK: attributes #[[ATTR3]] = { cold memory(none) }
-; CHECK: attributes #[[ATTR4]] = { strictfp }
+; CHECK: attributes #[[ATTR3]] = { strictfp }
;.
More information about the llvm-commits
mailing list