[llvm] [LICM] Don't hoist NOT out of loop if it can be fold into ANDN/ORN/XNOR (PR #130986)
Piotr Fusik via llvm-commits
llvm-commits at lists.llvm.org
Wed Mar 12 09:20:32 PDT 2025
https://github.com/pfusik created https://github.com/llvm/llvm-project/pull/130986
Fix #108840
>From d8c58f62bd0f0fbe8d3c7dd389623859c8defc93 Mon Sep 17 00:00:00 2001
From: Piotr Fusik <p.fusik at samsung.com>
Date: Wed, 12 Mar 2025 17:18:50 +0100
Subject: [PATCH] [LICM] Don't hoist NOT out of loop if it can be fold into
ANDN/ORN/XNOR
Fix #108840
---
llvm/lib/Transforms/Scalar/LICM.cpp | 9 +++++++++
llvm/lib/Transforms/Vectorize/VPlanTransforms.cpp | 2 +-
2 files changed, 10 insertions(+), 1 deletion(-)
diff --git a/llvm/lib/Transforms/Scalar/LICM.cpp b/llvm/lib/Transforms/Scalar/LICM.cpp
index 4bad19e6fb7be..51af462a553cc 100644
--- a/llvm/lib/Transforms/Scalar/LICM.cpp
+++ b/llvm/lib/Transforms/Scalar/LICM.cpp
@@ -1168,6 +1168,15 @@ bool llvm::canSinkOrHoistInst(Instruction &I, AAResults *AA, DominatorTree *DT,
if (!isHoistableAndSinkableInst(I))
return false;
+ if (I.getOpcode() == Instruction::Xor) {
+ Constant *C = dyn_cast<Constant>(I.getOperand(1));
+ if (C && C->isAllOnesValue() && all_of(I.users(), [](const User *U) {
+ auto *UI = dyn_cast<Instruction>(U);
+ return UI && UI->isBitwiseLogicOp();
+ }))
+ return false;
+ }
+
MemorySSA *MSSA = MSSAU.getMemorySSA();
// Loads have extra constraints we have to verify before we can hoist them.
if (LoadInst *LI = dyn_cast<LoadInst>(&I)) {
diff --git a/llvm/lib/Transforms/Vectorize/VPlanTransforms.cpp b/llvm/lib/Transforms/Vectorize/VPlanTransforms.cpp
index ecf52673480e2..20b3801e6cfa2 100644
--- a/llvm/lib/Transforms/Vectorize/VPlanTransforms.cpp
+++ b/llvm/lib/Transforms/Vectorize/VPlanTransforms.cpp
@@ -1329,7 +1329,7 @@ static void licm(VPlan &Plan) {
return !Op->isDefinedOutsideLoopRegions();
}))
continue;
- R.moveBefore(*Preheader, Preheader->end());
+ R.moveBefore(*Preheader, Preheader->end()); // TODO
}
}
}
More information about the llvm-commits
mailing list