diff --git a/llvm/test/tools/llvm-reduce/operands-to-args-target-ext-type.ll b/llvm/test/tools/llvm-reduce/operands-to-args-target-ext-type.ll new file mode 100644 index 0000000000000..cafd460f14ab3 --- /dev/null +++ b/llvm/test/tools/llvm-reduce/operands-to-args-target-ext-type.ll @@ -0,0 +1,32 @@ +; 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 +; RUN: FileCheck %s --input-file %t --check-prefixes=RESULT + +; Make sure there's no assert from trying to create a +; not-zeroinitializable target ext type + + +declare void @uses_ext_ty(target("sometarget.sometype")) +declare target("sometarget.sometype") @produces_ext_ty() + +; INTERESTING: define void @not_zero_foldable( + +; RESULT: define void @not_zero_foldable(target("sometarget.sometype") %call) { +; RESULT-NEXT: %call1 = call target("sometarget.sometype") @produces_ext_ty() +; RESULT-NEXT: call void @uses_ext_ty(target("sometarget.sometype") %call) +define void @not_zero_foldable() { + %call = call target("sometarget.sometype") @produces_ext_ty() + call void @uses_ext_ty(target("sometarget.sometype") %call) + ret void +} + +declare void @uses_zeroinit_ext_ty(target("spirv.zeroinit")) +declare target("sometarget.sometype") @produces_zeroinit_ext_ty() + +; INTERESTING: define void @foldable_to_zero( +; RESULT: define void @foldable_to_zero(target("spirv.zeroinit") %call) { +define void @foldable_to_zero() { + %call = call target("spirv.zeroinit") @produces_zeroinit_ext_ty() + call void @uses_zeroinit_ext_ty(target("spirv.zeroinit") %call) + ret void +} + diff --git a/llvm/test/tools/llvm-reduce/reduce-args-target-ext-ty.ll b/llvm/test/tools/llvm-reduce/reduce-args-target-ext-ty.ll new file mode 100644 index 0000000000000..e3a7e80f5e4ef --- /dev/null +++ b/llvm/test/tools/llvm-reduce/reduce-args-target-ext-ty.ll @@ -0,0 +1,13 @@ +; 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 +; RUN: FileCheck %s --input-file %t --check-prefixes=RESULT + +declare void @uses_ext_ty(target("sometarget.sometype")) +declare target("sometarget.sometype") @produces_ext_ty() + +; INTERESTING: @interesting( +; RESULT: @interesting( +; RESULT: void @uses_ext_ty() +define void @interesting(target("sometarget.sometype") %arg) { + call void @uses_ext_ty(target("sometarget.sometype") %arg) + ret void +} diff --git a/llvm/tools/llvm-reduce/deltas/Utils.cpp b/llvm/tools/llvm-reduce/deltas/Utils.cpp index 669b9db8a825a..92a44921a7cfb 100644 --- a/llvm/tools/llvm-reduce/deltas/Utils.cpp +++ b/llvm/tools/llvm-reduce/deltas/Utils.cpp @@ -24,7 +24,16 @@ cl::opt llvm::Verbose("verbose", cl::init(false), cl::cat(LLVMReduceOptions)); Value *llvm::getDefaultValue(Type *T) { - return T->isVoidTy() ? PoisonValue::get(T) : Constant::getNullValue(T); + if (T->isVoidTy()) + return PoisonValue::get(T); + + if (auto *TET = dyn_cast(T)) { + if (TET->hasProperty(TargetExtType::HasZeroInit)) + return ConstantTargetNone::get(TET); + return PoisonValue::get(TET); + } + + return Constant::getNullValue(T); } bool llvm::hasAliasUse(Function &F) {