[llvm] [CodeGen] Fix lower constant intrinsics for dead code (PR #102442)

via llvm-commits llvm-commits at lists.llvm.org
Thu Aug 8 02:21:32 PDT 2024


llvmbot wrote:


<!--LLVM PR SUMMARY COMMENT-->

@llvm/pr-subscribers-llvm-transforms

Author: Alexis Engelke (aengelke)

<details>
<summary>Changes</summary>

lowerConstantIntrinsics does an RPO traveral, which doesn't reach dead blocks. Remove the assertion that all intrinsics are lowered, because some intrinsics might remain.

---
Full diff: https://github.com/llvm/llvm-project/pull/102442.diff


2 Files Affected:

- (modified) llvm/lib/CodeGen/PreISelIntrinsicLowering.cpp (+1-1) 
- (added) llvm/test/Transforms/PreISelIntrinsicLowering/constant-intrinscs-dead-code.ll (+31) 


``````````diff
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
+}

``````````

</details>


https://github.com/llvm/llvm-project/pull/102442


More information about the llvm-commits mailing list