[PATCH] D133426: [LICM][LSR] Address a couple of special cases involving NULL.
Stefan Pintilie via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Wed Sep 7 07:47:01 PDT 2022
stefanp created this revision.
stefanp added reviewers: lei, nemanjai.
Herald added subscribers: asbirlea, hiraditya.
Herald added a project: All.
stefanp requested review of this revision.
Herald added a project: LLVM.
While looking at tests with opaque pointers it was noticed that LICM and
Loop Strength reduction behave differently in cases when a pointer is NULL.
This patch adds special cases to deal with NULL.
Repository:
rG LLVM Github Monorepo
https://reviews.llvm.org/D133426
Files:
llvm/lib/Transforms/Scalar/LICM.cpp
llvm/lib/Transforms/Scalar/LoopStrengthReduce.cpp
Index: llvm/lib/Transforms/Scalar/LoopStrengthReduce.cpp
===================================================================
--- llvm/lib/Transforms/Scalar/LoopStrengthReduce.cpp
+++ llvm/lib/Transforms/Scalar/LoopStrengthReduce.cpp
@@ -3471,9 +3471,14 @@
if (const Instruction *Inst = dyn_cast<Instruction>(V)) {
// Look for instructions defined outside the loop.
if (L->contains(Inst)) continue;
- } else if (isa<UndefValue>(V))
+ } else if (isa<UndefValue>(V)) {
// Undef doesn't have a live range, so it doesn't matter.
continue;
+ } else if (const Constant *Const = dyn_cast<Constant>(V)) {
+ // NULL values don't really have a live range. They are just NULL.
+ if (Const->isNullValue())
+ continue;
+ }
for (const Use &U : V->uses()) {
const Instruction *UserInst = dyn_cast<Instruction>(U.getUser());
// Ignore non-instructions.
Index: llvm/lib/Transforms/Scalar/LICM.cpp
===================================================================
--- llvm/lib/Transforms/Scalar/LICM.cpp
+++ llvm/lib/Transforms/Scalar/LICM.cpp
@@ -2092,9 +2092,14 @@
Store->getPointerOperand(), Store->getValueOperand()->getType(),
Store->getAlign(), MDL, Preheader->getTerminator(), DT, TLI);
}
- } else
- return false; // Not a load or store.
-
+ } else {
+ // Uses of null that are not loads or stores can be ignored.
+ if (const Constant *Const = dyn_cast<Constant>(ASIV)) {
+ if (Const->isNullValue())
+ continue;
+ }
+ return false; // Not a load or store and not null.
+ }
if (!AccessTy)
AccessTy = getLoadStoreType(UI);
else if (AccessTy != getLoadStoreType(UI))
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D133426.458454.patch
Type: text/x-patch
Size: 1797 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20220907/0ad62d82/attachment.bin>
More information about the llvm-commits
mailing list