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

Matt Arsenault via llvm-commits llvm-commits at lists.llvm.org
Fri Mar 28 00:12:07 PDT 2025


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

>From 705dd280d36c1e06fa9239e9b8694419fa4760b6 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/DeltaManager.cpp       |  1 +
 .../llvm-reduce/deltas/ReduceOperands.cpp     | 22 +++++++++++++++++--
 .../tools/llvm-reduce/deltas/ReduceOperands.h |  1 +
 4 files changed, 27 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/DeltaManager.cpp b/llvm/tools/llvm-reduce/DeltaManager.cpp
index 624b5306bc71b..7ec9cf28f6fe0 100644
--- a/llvm/tools/llvm-reduce/DeltaManager.cpp
+++ b/llvm/tools/llvm-reduce/DeltaManager.cpp
@@ -104,6 +104,7 @@ static cl::list<std::string>
     DELTA_PASS("operands-zero", reduceOperandsZeroDeltaPass)                   \
     DELTA_PASS("operands-one", reduceOperandsOneDeltaPass)                     \
     DELTA_PASS("operands-nan", reduceOperandsNaNDeltaPass)                     \
+    DELTA_PASS("operands-poison", reduceOperandsPoisonDeltaPass)               \
     DELTA_PASS("operands-to-args", reduceOperandsToArgsDeltaPass)              \
     DELTA_PASS("operands-skip", reduceOperandsSkipDeltaPass)                   \
     DELTA_PASS("operand-bundles", reduceOperandBundesDeltaPass)                \
diff --git a/llvm/tools/llvm-reduce/deltas/ReduceOperands.cpp b/llvm/tools/llvm-reduce/deltas/ReduceOperands.cpp
index 5babdc7d0a940..1c0dd70666cb9 100644
--- a/llvm/tools/llvm-reduce/deltas/ReduceOperands.cpp
+++ b/llvm/tools/llvm-reduce/deltas/ReduceOperands.cpp
@@ -140,8 +140,6 @@ void llvm::reduceOperandsZeroDeltaPass(TestRunner &Test) {
         return nullptr;
       if (TET->hasProperty(TargetExtType::HasZeroInit))
         return ConstantTargetNone::get(TET);
-
-      // TODO: Poison reduction for this case
       return nullptr;
     }
 
@@ -183,3 +181,23 @@ void llvm::reduceOperandsNaNDeltaPass(TestRunner &Test) {
       },
       "Reducing Operands to NaN");
 }
+
+void llvm::reduceOperandsPoisonDeltaPass(TestRunner &Test) {
+  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;
+  };
+
+  runDeltaPass(
+      Test,
+      [ReduceValue](Oracle &O, ReducerWorkItem &Program) {
+        extractOperandsFromModule(O, Program, ReduceValue);
+      },
+      "Reducing Operands to poison");
+}
diff --git a/llvm/tools/llvm-reduce/deltas/ReduceOperands.h b/llvm/tools/llvm-reduce/deltas/ReduceOperands.h
index b4a18998f8e20..832029ccea344 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(TestRunner &Test);
 void reduceOperandsZeroDeltaPass(TestRunner &Test);
 void reduceOperandsNaNDeltaPass(TestRunner &Test);
+void reduceOperandsPoisonDeltaPass(TestRunner &Test);
 } // namespace llvm
 
 #endif



More information about the llvm-commits mailing list