Skip to content

Commit caedfd8

Browse files
committed
llvm-reduce: Fix asserting on TargetExtTypes that do not support zeroinit
So far I've been unsuccessful in finding an example where the used constant value is directly observed in the output. This avoids an assert in an intermediate step of value replacement.
1 parent 9fe77ab commit caedfd8

File tree

3 files changed

+55
-1
lines changed

3 files changed

+55
-1
lines changed
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
; RUN: llvm-reduce %s -o %t --abort-on-invalid-reduction --delta-passes=operands-to-args --test FileCheck --test-arg %s --test-arg --check-prefixes=INTERESTING --test-arg --input-file
2+
; RUN: FileCheck %s --input-file %t --check-prefixes=RESULT
3+
4+
; Make sure there's no assert from trying to create a
5+
; not-zeroinitializable target ext type
6+
7+
8+
declare void @uses_ext_ty(target("sometarget.sometype"))
9+
declare target("sometarget.sometype") @produces_ext_ty()
10+
11+
; INTERESTING: define void @not_zero_foldable(
12+
13+
; RESULT: define void @not_zero_foldable(target("sometarget.sometype") %call) {
14+
; RESULT-NEXT: %call1 = call target("sometarget.sometype") @produces_ext_ty()
15+
; RESULT-NEXT: call void @uses_ext_ty(target("sometarget.sometype") %call)
16+
define void @not_zero_foldable() {
17+
%call = call target("sometarget.sometype") @produces_ext_ty()
18+
call void @uses_ext_ty(target("sometarget.sometype") %call)
19+
ret void
20+
}
21+
22+
declare void @uses_zeroinit_ext_ty(target("spirv.zeroinit"))
23+
declare target("sometarget.sometype") @produces_zeroinit_ext_ty()
24+
25+
; INTERESTING: define void @foldable_to_zero(
26+
; RESULT: define void @foldable_to_zero(target("spirv.zeroinit") %call) {
27+
define void @foldable_to_zero() {
28+
%call = call target("spirv.zeroinit") @produces_zeroinit_ext_ty()
29+
call void @uses_zeroinit_ext_ty(target("spirv.zeroinit") %call)
30+
ret void
31+
}
32+
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
; RUN: llvm-reduce %s -o %t --abort-on-invalid-reduction --delta-passes=arguments --test FileCheck --test-arg %s --test-arg --check-prefixes=INTERESTING --test-arg --input-file
2+
; RUN: FileCheck %s --input-file %t --check-prefixes=RESULT
3+
4+
declare void @uses_ext_ty(target("sometarget.sometype"))
5+
declare target("sometarget.sometype") @produces_ext_ty()
6+
7+
; INTERESTING: @interesting(
8+
; RESULT: @interesting(
9+
; RESULT: void @uses_ext_ty()
10+
define void @interesting(target("sometarget.sometype") %arg) {
11+
call void @uses_ext_ty(target("sometarget.sometype") %arg)
12+
ret void
13+
}

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

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,16 @@ cl::opt<bool> llvm::Verbose("verbose",
2424
cl::init(false), cl::cat(LLVMReduceOptions));
2525

2626
Value *llvm::getDefaultValue(Type *T) {
27-
return T->isVoidTy() ? PoisonValue::get(T) : Constant::getNullValue(T);
27+
if (T->isVoidTy())
28+
return PoisonValue::get(T);
29+
30+
if (auto *TET = dyn_cast<TargetExtType>(T)) {
31+
if (TET->hasProperty(TargetExtType::HasZeroInit))
32+
return ConstantTargetNone::get(TET);
33+
return PoisonValue::get(TET);
34+
}
35+
36+
return Constant::getNullValue(T);
2837
}
2938

3039
bool llvm::hasAliasUse(Function &F) {

0 commit comments

Comments
 (0)