[llvm] [AArch64][InstCombine] Eliminate redundant barrier intrinsics (PR #112023)

David Sherwood via llvm-commits llvm-commits at lists.llvm.org
Mon Oct 14 08:49:41 PDT 2024


================
@@ -2150,13 +2150,42 @@ static std::optional<Instruction *> instCombineSVEInsr(InstCombiner &IC,
   return std::nullopt;
 }
 
+static std::optional<Instruction *> instCombineDMB(InstCombiner &IC,
+                                                   IntrinsicInst &II) {
+  // If this barrier is post-dominated by identical one we can remove it
+  auto *NI = II.getNextNonDebugInstruction();
+  int LookaheadThreshold = 10;
+  auto CanSkipOver = [](Instruction *I) {
+    return !I->mayReadOrWriteMemory() && !I->mayHaveSideEffects();
+  };
+  while (--LookaheadThreshold && !isa<IntrinsicInst>(NI)) {
+    if (!CanSkipOver(NI))
+      break;
+    auto *NIBB = NI->getParent();
+    NI = NI->getNextNonDebugInstruction();
+    if (!NI) {
+      if (auto *SuccBB = NIBB->getUniqueSuccessor())
+        NI = SuccBB->getFirstNonPHIOrDbgOrLifetime();
+      else
+        break;
+    }
+  }
+  auto *NextDMB = dyn_cast_or_null<IntrinsicInst>(NI);
----------------
david-arm wrote:

This isn't necessarily a DMB intrinsic so is it worth renaming this to be `NextII` or something like that?

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


More information about the llvm-commits mailing list