[llvm] [IPSCCP] Don't replace with constant if Value is noalias ptr or derivatives (PR #154522)
via llvm-commits
llvm-commits at lists.llvm.org
Wed Aug 20 05:19:56 PDT 2025
https://github.com/choikwa created https://github.com/llvm/llvm-project/pull/154522
This was motivated from looking at composable kernel benchmark where IPSCCP was observed replacing noalias ptr's and their derivatives with a global alias. Doing so would lose the noalias information and target backend was more pessimistic, emitting unneeded WAITCNT instructions.
Making it a draft as it's unclear if it's beneficially moving the needle.
>From 86ad532a7df8572b56b4fbf43b7dccf0b507b299 Mon Sep 17 00:00:00 2001
From: Kevin Choi <kevin.choi at amd.com>
Date: Wed, 20 Aug 2025 07:09:42 -0500
Subject: [PATCH] [IPSCCP] Don't replace with constant if Value is noalias ptr
or derivatives
This was motivated from looking at composable kernel benchmark where IPSCCP was observed replacing noalias ptr's and their derivatives with a global alias.
Doing so would lose the noalias information and target backend was more pessimistic, emitting unneeded WAITCNT instructions.
---
llvm/lib/Transforms/Utils/SCCPSolver.cpp | 15 +++++++++++++++
1 file changed, 15 insertions(+)
diff --git a/llvm/lib/Transforms/Utils/SCCPSolver.cpp b/llvm/lib/Transforms/Utils/SCCPSolver.cpp
index 84485176ad4ff..3c06452a91f36 100644
--- a/llvm/lib/Transforms/Utils/SCCPSolver.cpp
+++ b/llvm/lib/Transforms/Utils/SCCPSolver.cpp
@@ -62,6 +62,21 @@ bool SCCPSolver::tryToReplaceWithConstant(Value *V) {
Constant *Const = getConstantOrNull(V);
if (!Const)
return false;
+
+ // Don't replace noalias arg or derivatives
+ if (isa<PointerType>(V->getType())) {
+ SmallVector<const Value *, 4> Objects;
+ getUnderlyingObjects(V, Objects, nullptr);
+
+ for (const auto Obj : Objects) {
+ if (const auto *Arg = dyn_cast<Argument>(Obj)) {
+ if (isa<PointerType>(Arg->getType()) &&
+ Arg->hasNoAliasAttr())
+ return false;
+ }
+ }
+ }
+
// Replacing `musttail` instructions with constant breaks `musttail` invariant
// unless the call itself can be removed.
// Calls with "clang.arc.attachedcall" implicitly use the return value and
More information about the llvm-commits
mailing list