[llvm] [LoopVersioningLICM] Only mark pointers with generated checks as noalias (PR #135168)

John Brawn via llvm-commits llvm-commits at lists.llvm.org
Thu May 8 09:52:15 PDT 2025


================
@@ -344,6 +343,13 @@ bool LoopVersioningLICM::instructionSafeForVersioning(Instruction *I) {
     }
     LoadAndStoreCounter++;
     Value *Ptr = St->getPointerOperand();
+    // Don't allow stores that we don't have runtime checks for, as we won't be
+    // able to mark them noalias meaning they would prevent any code motion.
+    auto &Pointers = LAI->getRuntimePointerChecking()->Pointers;
+    if (!any_of(Pointers, [&](auto &P) { return P.PointerValue == Ptr; })) {
+      LLVM_DEBUG(dbgs() << "    Found a store without a runtime check.\n");
+      return false;
+    }
----------------
john-brawn-arm wrote:

Yes, this is a profitability check. An example of where we need this is the function gep_loaded_offset_with_store in the added load-from-unknown-address.ll test. Without this check we version the loop, but LICM can't do anything and we end up with two identical copies of the loop. We could possibly have a more precise check here, but I think that's something to look at in the future not in this patch.

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


More information about the llvm-commits mailing list