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

via llvm-commits llvm-commits at lists.llvm.org
Tue Apr 1 23:38:49 PDT 2025


Author: Matt Arsenault
Date: 2025-04-02T13:38:46+07:00
New Revision: 964650b69e57d5e9e6102a4b400c8da16f6a1e27

URL: https://github.com/llvm/llvm-project/commit/964650b69e57d5e9e6102a4b400c8da16f6a1e27
DIFF: https://github.com/llvm/llvm-project/commit/964650b69e57d5e9e6102a4b400c8da16f6a1e27.diff

LOG: llvm-reduce: Add reduceOperandsToPoison reduction (#132862)

For now use it only for TargetExtTypes, which do not always support
zero initializers.

Added: 
    

Modified: 
    llvm/test/tools/llvm-reduce/reduce-operands-target-ext-ty.ll
    llvm/tools/llvm-reduce/DeltaPasses.def
    llvm/tools/llvm-reduce/deltas/ReduceOperands.cpp
    llvm/tools/llvm-reduce/deltas/ReduceOperands.h

Removed: 
    


################################################################################
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 4c9c581924321..84d01ab6646b8 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