llvm-reduce: Add reduceOperandsToPoison reduction (#132862)
For now use it only for TargetExtTypes, which do not always support
zero initializers.
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 1e1a8e7e..b3548db 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 @@
; 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 4c9c581..84d01ab 100644
--- a/llvm/tools/llvm-reduce/DeltaPasses.def
+++ b/llvm/tools/llvm-reduce/DeltaPasses.def
@@ -41,6 +41,7 @@
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 c135f0c..a4fdd9c 100644
--- a/llvm/tools/llvm-reduce/deltas/ReduceOperands.cpp
+++ b/llvm/tools/llvm-reduce/deltas/ReduceOperands.cpp
@@ -135,8 +135,6 @@
return nullptr;
if (TET->hasProperty(TargetExtType::HasZeroInit))
return ConstantTargetNone::get(TET);
-
- // TODO: Poison reduction for this case
return nullptr;
}
@@ -168,3 +166,18 @@
};
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 2c86ba9..cdd5a08 100644
--- a/llvm/tools/llvm-reduce/deltas/ReduceOperands.h
+++ b/llvm/tools/llvm-reduce/deltas/ReduceOperands.h
@@ -15,6 +15,7 @@
void reduceOperandsOneDeltaPass(Oracle &, ReducerWorkItem &);
void reduceOperandsZeroDeltaPass(Oracle &, ReducerWorkItem &);
void reduceOperandsNaNDeltaPass(Oracle &, ReducerWorkItem &);
+void reduceOperandsPoisonDeltaPass(Oracle &, ReducerWorkItem &);
} // namespace llvm
#endif