[llvm] 5313d2e - [CodeGen] Fix lower constant intrinsics for dead code (#102442)
via llvm-commits
llvm-commits at lists.llvm.org
Thu Aug 8 04:06:38 PDT 2024
Author: Alexis Engelke
Date: 2024-08-08T13:06:33+02:00
New Revision: 5313d2e6d02d2a8b192e2c007241ff261287e1ca
URL: https://github.com/llvm/llvm-project/commit/5313d2e6d02d2a8b192e2c007241ff261287e1ca
DIFF: https://github.com/llvm/llvm-project/commit/5313d2e6d02d2a8b192e2c007241ff261287e1ca.diff
LOG: [CodeGen] Fix lower constant intrinsics for dead code (#102442)
lowerConstantIntrinsics does an RPO traveral, which doesn't reach dead
blocks. Remove the assertion that all intrinsics are lowered, because
some intrinsics might remain.
Added:
llvm/test/Transforms/PreISelIntrinsicLowering/constant-intrinscs-dead-code.ll
Modified:
llvm/lib/CodeGen/PreISelIntrinsicLowering.cpp
Removed:
################################################################################
diff --git a/llvm/lib/CodeGen/PreISelIntrinsicLowering.cpp b/llvm/lib/CodeGen/PreISelIntrinsicLowering.cpp
index 0d3dd650b8ee68..0df90f402aaf48 100644
--- a/llvm/lib/CodeGen/PreISelIntrinsicLowering.cpp
+++ b/llvm/lib/CodeGen/PreISelIntrinsicLowering.cpp
@@ -349,8 +349,8 @@ bool PreISelIntrinsicLowering::lowerIntrinsics(Module &M) const {
Changed |= forEachCall(F, [&](CallInst *CI) {
Function *Parent = CI->getParent()->getParent();
TargetLibraryInfo &TLI = LookupTLI(*Parent);
+ // Intrinsics in unreachable code are not lowered.
bool Changed = lowerConstantIntrinsics(*Parent, TLI, /*DT=*/nullptr);
- assert(Changed && "lowerConstantIntrinsics did not lower intrinsic");
return Changed;
});
break;
diff --git a/llvm/test/Transforms/PreISelIntrinsicLowering/constant-intrinscs-dead-code.ll b/llvm/test/Transforms/PreISelIntrinsicLowering/constant-intrinscs-dead-code.ll
new file mode 100644
index 00000000000000..35de92372cb9fc
--- /dev/null
+++ b/llvm/test/Transforms/PreISelIntrinsicLowering/constant-intrinscs-dead-code.ll
@@ -0,0 +1,31 @@
+; NOTE: Assertions have been autogenerated by utils/update_test_checks.py UTC_ARGS: --version 5
+; RUN: opt -S < %s -passes=pre-isel-intrinsic-lowering | FileCheck %s
+
+define void @test_dead() {
+; CHECK-LABEL: define void @test_dead() {
+; CHECK-NEXT: ret void
+; CHECK: [[DEAD:.*]]:
+; CHECK-NEXT: [[X:%.*]] = call i32 @llvm.objectsize.i32.p21(ptr addrspace(21) null, i1 false, i1 false, i1 false)
+; CHECK-NEXT: br label %[[DEAD]]
+;
+ ret void
+
+dead:
+ %x = call i32 @llvm.objectsize.i32.p21(ptr addrspace(21) null, i1 false, i1 false, i1 false)
+ br label %dead
+}
+
+define i32 @test_two() {
+; CHECK-LABEL: define i32 @test_two() {
+; CHECK-NEXT: ret i32 -1
+; CHECK: [[DEAD:.*]]:
+; CHECK-NEXT: [[X:%.*]] = call i32 @llvm.objectsize.i32.p21(ptr addrspace(21) null, i1 false, i1 false, i1 false)
+; CHECK-NEXT: br label %[[DEAD]]
+;
+ %a = call i32 @llvm.objectsize.i32.p21(ptr addrspace(21) null, i1 false, i1 false, i1 false)
+ ret i32 %a
+
+dead:
+ %x = call i32 @llvm.objectsize.i32.p21(ptr addrspace(21) null, i1 false, i1 false, i1 false)
+ br label %dead
+}
More information about the llvm-commits
mailing list