Skip to content

Commit 7271ac9

Browse files
committed
llvm-reduce: Add reduceOperandsToPoison reduction
For now use it only for TargetExtTypes, which do not always support zero initializers.
1 parent 2eab5bb commit 7271ac9

File tree

4 files changed

+27
-2
lines changed

4 files changed

+27
-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/DeltaManager.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,7 @@ static cl::list<std::string>
104104
DELTA_PASS("operands-zero", reduceOperandsZeroDeltaPass) \
105105
DELTA_PASS("operands-one", reduceOperandsOneDeltaPass) \
106106
DELTA_PASS("operands-nan", reduceOperandsNaNDeltaPass) \
107+
DELTA_PASS("operands-poison", reduceOperandsPoisonDeltaPass) \
107108
DELTA_PASS("operands-to-args", reduceOperandsToArgsDeltaPass) \
108109
DELTA_PASS("operands-skip", reduceOperandsSkipDeltaPass) \
109110
DELTA_PASS("operand-bundles", reduceOperandBundesDeltaPass) \

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

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -140,8 +140,6 @@ void llvm::reduceOperandsZeroDeltaPass(TestRunner &Test) {
140140
return nullptr;
141141
if (TET->hasProperty(TargetExtType::HasZeroInit))
142142
return ConstantTargetNone::get(TET);
143-
144-
// TODO: Poison reduction for this case
145143
return nullptr;
146144
}
147145

@@ -183,3 +181,23 @@ void llvm::reduceOperandsNaNDeltaPass(TestRunner &Test) {
183181
},
184182
"Reducing Operands to NaN");
185183
}
184+
185+
void llvm::reduceOperandsPoisonDeltaPass(TestRunner &Test) {
186+
auto ReduceValue = [](Use &Op) -> Value * {
187+
Type *Ty = Op->getType();
188+
if (auto *TET = dyn_cast<TargetExtType>(Ty)) {
189+
if (isa<ConstantTargetNone, PoisonValue>(Op))
190+
return nullptr;
191+
return PoisonValue::get(TET);
192+
}
193+
194+
return nullptr;
195+
};
196+
197+
runDeltaPass(
198+
Test,
199+
[ReduceValue](Oracle &O, ReducerWorkItem &Program) {
200+
extractOperandsFromModule(O, Program, ReduceValue);
201+
},
202+
"Reducing Operands to poison");
203+
}

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(TestRunner &Test);
1616
void reduceOperandsZeroDeltaPass(TestRunner &Test);
1717
void reduceOperandsNaNDeltaPass(TestRunner &Test);
18+
void reduceOperandsPoisonDeltaPass(TestRunner &Test);
1819
} // namespace llvm
1920

2021
#endif

0 commit comments

Comments
 (0)