[llvm] llvm-reduce: Add reduceOperandsToPoison reduction (PR #132862)

Matt Arsenault via llvm-commits llvm-commits at lists.llvm.org
Sun Mar 30 03:46:23 PDT 2025


https://github.com/arsenm updated https://github.com/llvm/llvm-project/pull/132862

>From 7e067d4320ed359eba3cd0e6b2dd86c7a9fd2697 Mon Sep 17 00:00:00 2001
From: Matt Arsenault <Matthew.Arsenault at amd.com>
Date: Tue, 25 Mar 2025 09:27:35 +0700
Subject: [PATCH] llvm-reduce: Add reduceOperandsToPoison reduction

For now use it only for TargetExtTypes, which do not always support
zero initializers.
---
 .../reduce-operands-target-ext-ty.ll            |  5 +++++
 llvm/tools/llvm-reduce/DeltaPasses.def          |  1 +
 .../tools/llvm-reduce/deltas/ReduceOperands.cpp | 17 +++++++++++++++--
 llvm/tools/llvm-reduce/deltas/ReduceOperands.h  |  1 +
 4 files changed, 22 insertions(+), 2 deletions(-)

diff --git a/llvm/test/tools/llvm-reduce/reduce-operands-target-ext-ty.ll b/llvm/test/tools/llvm-reduce/reduce-operands-target-ext-ty.ll
index 1e1a8e7ec5e07..b3548dbb569db 100644
--- a/llvm/test/tools/llvm-reduce/reduce-operands-target-ext-ty.ll
+++ b/llvm/test/tools/llvm-reduce/reduce-operands-target-ext-ty.ll
@@ -4,12 +4,16 @@
 ; RUN: llvm-reduce --abort-on-invalid-reduction --delta-passes=operands-one --test FileCheck --test-arg %s --test-arg --input-file %s -o %t
 ; RUN: FileCheck --check-prefixes=CHECK,ONE %s < %t
 
+; RUN: llvm-reduce --abort-on-invalid-reduction --delta-passes=operands-poison --test FileCheck --test-arg %s --test-arg --input-file %s -o %t
+; RUN: FileCheck --check-prefixes=CHECK,POISON %s < %t
+
 declare void @uses_ext_ty(target("sometarget.sometype"))
 
 ; TODO: Should support reduce to poison
 ; CHECK-LABEL: @foo(
 ; ZERO: call void @uses_ext_ty(target("sometarget.sometype") %arg)
 ; ONE: call void @uses_ext_ty(target("sometarget.sometype") %arg)
+; POISON: call void @uses_ext_ty(target("sometarget.sometype") poison)
 define void @foo(target("sometarget.sometype") %arg) {
   call void @uses_ext_ty(target("sometarget.sometype") %arg)
   ret void
@@ -20,6 +24,7 @@ declare void @uses_zeroinit_ext_ty(target("sometarget.sometype"))
 ; CHECK-LABEL: @bar(
 ; ZERO: call void @uses_zeroinit_ext_ty(target("spirv.sometype") zeroinitializer)
 ; ONE: call void @uses_zeroinit_ext_ty(target("spirv.sometype") %arg)
+; POISON: call void @uses_zeroinit_ext_ty(target("spirv.sometype") poison)
 define void @bar(target("spirv.sometype") %arg) {
   call void @uses_zeroinit_ext_ty(target("spirv.sometype") %arg)
   ret void
diff --git a/llvm/tools/llvm-reduce/DeltaPasses.def b/llvm/tools/llvm-reduce/DeltaPasses.def
index 060daf198c76a..e6b0391e83024 100644
--- a/llvm/tools/llvm-reduce/DeltaPasses.def
+++ b/llvm/tools/llvm-reduce/DeltaPasses.def
@@ -41,6 +41,7 @@ DELTA_PASS_IR("ir-passes", runIRPassesDeltaPass, "Running passes")
 DELTA_PASS_IR("operands-zero", reduceOperandsZeroDeltaPass, "Reducing Operands to zero")
 DELTA_PASS_IR("operands-one", reduceOperandsOneDeltaPass, "Reducing Operands to one")
 DELTA_PASS_IR("operands-nan", reduceOperandsNaNDeltaPass, "Reducing Operands to NaN")
+DELTA_PASS_IR("operands-poison", reduceOperandsPoisonDeltaPass, "Reducing Operands to poison")
 DELTA_PASS_IR("operands-to-args", reduceOperandsToArgsDeltaPass, "Converting operands to function arguments")
 DELTA_PASS_IR("operands-skip", reduceOperandsSkipDeltaPass, "Reducing operands by skipping over instructions")
 DELTA_PASS_IR("operand-bundles", reduceOperandBundesDeltaPass, "Reducing Operand Bundles")
diff --git a/llvm/tools/llvm-reduce/deltas/ReduceOperands.cpp b/llvm/tools/llvm-reduce/deltas/ReduceOperands.cpp
index c135f0c9e5c36..a4fdd9ce8033b 100644
--- a/llvm/tools/llvm-reduce/deltas/ReduceOperands.cpp
+++ b/llvm/tools/llvm-reduce/deltas/ReduceOperands.cpp
@@ -135,8 +135,6 @@ void llvm::reduceOperandsZeroDeltaPass(Oracle &O, ReducerWorkItem &WorkItem) {
         return nullptr;
       if (TET->hasProperty(TargetExtType::HasZeroInit))
         return ConstantTargetNone::get(TET);
-
-      // TODO: Poison reduction for this case
       return nullptr;
     }
 
@@ -168,3 +166,18 @@ void llvm::reduceOperandsNaNDeltaPass(Oracle &O, ReducerWorkItem &WorkItem) {
   };
   extractOperandsFromModule(O, WorkItem, ReduceValue);
 }
+
+void llvm::reduceOperandsPoisonDeltaPass(Oracle &O, ReducerWorkItem &WorkItem) {
+  auto ReduceValue = [](Use &Op) -> Value * {
+    Type *Ty = Op->getType();
+    if (auto *TET = dyn_cast<TargetExtType>(Ty)) {
+      if (isa<ConstantTargetNone, PoisonValue>(Op))
+        return nullptr;
+      return PoisonValue::get(TET);
+    }
+
+    return nullptr;
+  };
+
+  extractOperandsFromModule(O, WorkItem, ReduceValue);
+}
diff --git a/llvm/tools/llvm-reduce/deltas/ReduceOperands.h b/llvm/tools/llvm-reduce/deltas/ReduceOperands.h
index 2c86ba920442b..cdd5a08056ca5 100644
--- a/llvm/tools/llvm-reduce/deltas/ReduceOperands.h
+++ b/llvm/tools/llvm-reduce/deltas/ReduceOperands.h
@@ -15,6 +15,7 @@ namespace llvm {
 void reduceOperandsOneDeltaPass(Oracle &, ReducerWorkItem &);
 void reduceOperandsZeroDeltaPass(Oracle &, ReducerWorkItem &);
 void reduceOperandsNaNDeltaPass(Oracle &, ReducerWorkItem &);
+void reduceOperandsPoisonDeltaPass(Oracle &, ReducerWorkItem &);
 } // namespace llvm
 
 #endif



More information about the llvm-commits mailing list