Skip to content

Commit 964650b

Browse files
authored
llvm-reduce: Add reduceOperandsToPoison reduction (#132862)
For now use it only for TargetExtTypes, which do not always support zero initializers.
1 parent 076397f commit 964650b

File tree

4 files changed

+22
-2
lines changed

4 files changed

+22
-2
lines changed

llvm/test/tools/llvm-reduce/reduce-operands-target-ext-ty.ll

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,16 @@
44
; RUN: llvm-reduce --abort-on-invalid-reduction --delta-passes=operands-one --test FileCheck --test-arg %s --test-arg --input-file %s -o %t
55
; RUN: FileCheck --check-prefixes=CHECK,ONE %s < %t
66

7+
; RUN: llvm-reduce --abort-on-invalid-reduction --delta-passes=operands-poison --test FileCheck --test-arg %s --test-arg --input-file %s -o %t
8+
; RUN: FileCheck --check-prefixes=CHECK,POISON %s < %t
9+
710
declare void @uses_ext_ty(target("sometarget.sometype"))
811

912
; TODO: Should support reduce to poison
1013
; CHECK-LABEL: @foo(
1114
; ZERO: call void @uses_ext_ty(target("sometarget.sometype") %arg)
1215
; ONE: call void @uses_ext_ty(target("sometarget.sometype") %arg)
16+
; POISON: call void @uses_ext_ty(target("sometarget.sometype") poison)
1317
define void @foo(target("sometarget.sometype") %arg) {
1418
call void @uses_ext_ty(target("sometarget.sometype") %arg)
1519
ret void
@@ -20,6 +24,7 @@ declare void @uses_zeroinit_ext_ty(target("sometarget.sometype"))
2024
; CHECK-LABEL: @bar(
2125
; ZERO: call void @uses_zeroinit_ext_ty(target("spirv.sometype") zeroinitializer)
2226
; ONE: call void @uses_zeroinit_ext_ty(target("spirv.sometype") %arg)
27+
; POISON: call void @uses_zeroinit_ext_ty(target("spirv.sometype") poison)
2328
define void @bar(target("spirv.sometype") %arg) {
2429
call void @uses_zeroinit_ext_ty(target("spirv.sometype") %arg)
2530
ret void

llvm/tools/llvm-reduce/DeltaPasses.def

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ DELTA_PASS_IR("ir-passes", runIRPassesDeltaPass, "Running passes")
4141
DELTA_PASS_IR("operands-zero", reduceOperandsZeroDeltaPass, "Reducing Operands to zero")
4242
DELTA_PASS_IR("operands-one", reduceOperandsOneDeltaPass, "Reducing Operands to one")
4343
DELTA_PASS_IR("operands-nan", reduceOperandsNaNDeltaPass, "Reducing Operands to NaN")
44+
DELTA_PASS_IR("operands-poison", reduceOperandsPoisonDeltaPass, "Reducing Operands to poison")
4445
DELTA_PASS_IR("operands-to-args", reduceOperandsToArgsDeltaPass, "Converting operands to function arguments")
4546
DELTA_PASS_IR("operands-skip", reduceOperandsSkipDeltaPass, "Reducing operands by skipping over instructions")
4647
DELTA_PASS_IR("operand-bundles", reduceOperandBundesDeltaPass, "Reducing Operand Bundles")

llvm/tools/llvm-reduce/deltas/ReduceOperands.cpp

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -135,8 +135,6 @@ void llvm::reduceOperandsZeroDeltaPass(Oracle &O, ReducerWorkItem &WorkItem) {
135135
return nullptr;
136136
if (TET->hasProperty(TargetExtType::HasZeroInit))
137137
return ConstantTargetNone::get(TET);
138-
139-
// TODO: Poison reduction for this case
140138
return nullptr;
141139
}
142140

@@ -168,3 +166,18 @@ void llvm::reduceOperandsNaNDeltaPass(Oracle &O, ReducerWorkItem &WorkItem) {
168166
};
169167
extractOperandsFromModule(O, WorkItem, ReduceValue);
170168
}
169+
170+
void llvm::reduceOperandsPoisonDeltaPass(Oracle &O, ReducerWorkItem &WorkItem) {
171+
auto ReduceValue = [](Use &Op) -> Value * {
172+
Type *Ty = Op->getType();
173+
if (auto *TET = dyn_cast<TargetExtType>(Ty)) {
174+
if (isa<ConstantTargetNone, PoisonValue>(Op))
175+
return nullptr;
176+
return PoisonValue::get(TET);
177+
}
178+
179+
return nullptr;
180+
};
181+
182+
extractOperandsFromModule(O, WorkItem, ReduceValue);
183+
}

llvm/tools/llvm-reduce/deltas/ReduceOperands.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ namespace llvm {
1515
void reduceOperandsOneDeltaPass(Oracle &, ReducerWorkItem &);
1616
void reduceOperandsZeroDeltaPass(Oracle &, ReducerWorkItem &);
1717
void reduceOperandsNaNDeltaPass(Oracle &, ReducerWorkItem &);
18+
void reduceOperandsPoisonDeltaPass(Oracle &, ReducerWorkItem &);
1819
} // namespace llvm
1920

2021
#endif

0 commit comments

Comments
 (0)