[llvm] c0cabfb - [InstCombiner] Remove trivially dead `llvm.allow.{runtime,ubsan}.check()` (#84851)

via llvm-commits llvm-commits at lists.llvm.org
Mon Apr 1 00:42:21 PDT 2024


Author: Vitaly Buka
Date: 2024-04-01T00:42:18-07:00
New Revision: c0cabfbdaf547b1152065be5419bc48e0b83b761

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

LOG: [InstCombiner] Remove trivially dead `llvm.allow.{runtime,ubsan}.check()` (#84851)

Intrinsic declared to have sideeffects, but it's done only to prevent
moving it. Removing unused ones is OK.

Exacted from #84850 for easier review.

Added: 
    llvm/test/Transforms/InstCombine/allow-checks.ll

Modified: 
    llvm/lib/Transforms/Utils/Local.cpp

Removed: 
    


################################################################################
diff  --git a/llvm/lib/Transforms/Utils/Local.cpp b/llvm/lib/Transforms/Utils/Local.cpp
index 3d3b97eca92b3d..380bac9c618077 100644
--- a/llvm/lib/Transforms/Utils/Local.cpp
+++ b/llvm/lib/Transforms/Utils/Local.cpp
@@ -475,6 +475,12 @@ bool llvm::wouldInstructionBeTriviallyDead(const Instruction *I,
         II->getIntrinsicID() == Intrinsic::launder_invariant_group)
       return true;
 
+    // Intrinsics declare sideeffects to prevent them from moving, but they are
+    // nops without users.
+    if (II->getIntrinsicID() == Intrinsic::allow_runtime_check ||
+        II->getIntrinsicID() == Intrinsic::allow_ubsan_check)
+      return true;
+
     if (II->isLifetimeStartOrEnd()) {
       auto *Arg = II->getArgOperand(1);
       // Lifetime intrinsics are dead when their right-hand is undef.

diff  --git a/llvm/test/Transforms/InstCombine/allow-checks.ll b/llvm/test/Transforms/InstCombine/allow-checks.ll
new file mode 100644
index 00000000000000..873b7c3014a881
--- /dev/null
+++ b/llvm/test/Transforms/InstCombine/allow-checks.ll
@@ -0,0 +1,44 @@
+; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
+; RUN: opt < %s -passes=instcombine -S | FileCheck %s --implicit-check-not="call i1 @llvm.allow"
+
+define i1 @test_runtime()  {
+; CHECK-LABEL: @test_runtime(
+; CHECK-NEXT:  entry:
+; CHECK-NEXT:    [[HOT:%.*]] = call i1 @llvm.allow.runtime.check(metadata !"test")
+; CHECK-NEXT:    ret i1 [[HOT]]
+;
+entry:
+  %allow = call i1 @llvm.allow.runtime.check(metadata !"test")
+  ret i1 %allow
+}
+
+define void @test_runtime_void()  {
+; CHECK-LABEL: @test_runtime_void(
+; CHECK-NEXT:  entry:
+; CHECK-NEXT:    ret void
+;
+entry:
+  %allow = call i1 @llvm.allow.runtime.check(metadata !"test")
+  ret void
+}
+
+define i1 @test_ubsan()  {
+; CHECK-LABEL: @test_ubsan(
+; CHECK-NEXT:  entry:
+; CHECK-NEXT:    [[HOT:%.*]] = call i1 @llvm.allow.ubsan.check(i8 11)
+; CHECK-NEXT:    ret i1 [[HOT]]
+;
+entry:
+  %allow = call i1 @llvm.allow.ubsan.check(i8 11)
+  ret i1 %allow
+}
+
+define void @test_ubsan_void()  {
+; CHECK-LABEL: @test_ubsan_void(
+; CHECK-NEXT:  entry:
+; CHECK-NEXT:    ret void
+;
+entry:
+  %allow = call i1 @llvm.allow.ubsan.check(i8 11)
+  ret void
+}


        


More information about the llvm-commits mailing list