[llvm-branch-commits] [llvm] llvm-reduce: Handle the addrspacecast nonnull flag (PR #217907)
Matt Arsenault via llvm-branch-commits
llvm-branch-commits at lists.llvm.org
Fri Aug 21 05:49:43 PDT 2026
https://github.com/arsenm created https://github.com/llvm/llvm-project/pull/217907
Co-authored-by: Claude (Claude-Opus-4.8) <noreply at anthropic.com>
>From 16e4e6e824cd5a8a00ec1ba13f01a66531956c03 Mon Sep 17 00:00:00 2001
From: Matt Arsenault <Matthew.Arsenault at amd.com>
Date: Thu, 20 Aug 2026 22:00:37 +0200
Subject: [PATCH] llvm-reduce: Handle the addrspacecast nonnull flag
Co-authored-by: Claude (Claude-Opus-4.8) <noreply at anthropic.com>
---
llvm/test/tools/llvm-reduce/reduce-flags.ll | 24 +++++++++++++++++++
llvm/tools/llvm-reduce/ReducerWorkItem.cpp | 3 +++
.../deltas/ReduceInstructionFlags.cpp | 3 +++
3 files changed, 30 insertions(+)
diff --git a/llvm/test/tools/llvm-reduce/reduce-flags.ll b/llvm/test/tools/llvm-reduce/reduce-flags.ll
index f220fc429c89e..dd7610f583533 100644
--- a/llvm/test/tools/llvm-reduce/reduce-flags.ll
+++ b/llvm/test/tools/llvm-reduce/reduce-flags.ll
@@ -288,3 +288,27 @@ define i1 @icmp_samesign_keep(i32 %a) {
%op = icmp samesign ult i32 %a, 10
ret i1 %op
}
+
+; CHECK-LABEL: @addrspacecast_nonnull_drop(
+; INTERESTING: = addrspacecast
+; RESULT: addrspacecast ptr addrspace(1) %a to ptr
+define ptr @addrspacecast_nonnull_drop(ptr addrspace(1) %a) {
+ %op = addrspacecast nonnull ptr addrspace(1) %a to ptr
+ ret ptr %op
+}
+
+; CHECK-LABEL: @addrspacecast_nonnull_keep(
+; INTERESTING: = addrspacecast nonnull
+; RESULT: addrspacecast nonnull ptr addrspace(1) %a to ptr
+define ptr @addrspacecast_nonnull_keep(ptr addrspace(1) %a) {
+ %op = addrspacecast nonnull ptr addrspace(1) %a to ptr
+ ret ptr %op
+}
+
+; CHECK-LABEL: @addrspacecast_nonnull_vector_keep(
+; INTERESTING: = addrspacecast nonnull
+; RESULT: addrspacecast nonnull <2 x ptr addrspace(1)> %a to <2 x ptr>
+define <2 x ptr> @addrspacecast_nonnull_vector_keep(<2 x ptr addrspace(1)> %a) {
+ %op = addrspacecast nonnull <2 x ptr addrspace(1)> %a to <2 x ptr>
+ ret <2 x ptr> %op
+}
diff --git a/llvm/tools/llvm-reduce/ReducerWorkItem.cpp b/llvm/tools/llvm-reduce/ReducerWorkItem.cpp
index fa4da7a073f1e..9be05aafc865d 100644
--- a/llvm/tools/llvm-reduce/ReducerWorkItem.cpp
+++ b/llvm/tools/llvm-reduce/ReducerWorkItem.cpp
@@ -681,6 +681,9 @@ static uint64_t computeIRComplexityScoreImpl(const Function &F) {
} else if (const auto *PDI = dyn_cast<PossiblyDisjointInst>(&I)) {
if (PDI->isDisjoint())
++Score;
+ } else if (const auto *ASC = dyn_cast<AddrSpaceCastInst>(&I)) {
+ if (ASC->hasNonNull())
+ ++Score;
} else if (const auto *GEP = dyn_cast<GEPOperator>(&I)) {
if (GEP->isInBounds())
++Score;
diff --git a/llvm/tools/llvm-reduce/deltas/ReduceInstructionFlags.cpp b/llvm/tools/llvm-reduce/deltas/ReduceInstructionFlags.cpp
index 2937550bfec75..300747b4c5312 100644
--- a/llvm/tools/llvm-reduce/deltas/ReduceInstructionFlags.cpp
+++ b/llvm/tools/llvm-reduce/deltas/ReduceInstructionFlags.cpp
@@ -45,6 +45,9 @@ void llvm::reduceInstructionFlagsDeltaPass(Oracle &O,
} else if (auto *ICmp = dyn_cast<ICmpInst>(&I)) {
if (ICmp->hasSameSign() && !O.shouldKeep())
ICmp->setSameSign(false);
+ } else if (auto *ASC = dyn_cast<AddrSpaceCastInst>(&I)) {
+ if (ASC->hasNonNull() && !O.shouldKeep())
+ ASC->setNonNull(false);
} else if (auto *GEP = dyn_cast<GetElementPtrInst>(&I)) {
GEPNoWrapFlags NW = GEP->getNoWrapFlags();
if (NW.isInBounds() && !O.shouldKeep())
More information about the llvm-branch-commits
mailing list