Skip to content

llvm-reduce: Add values to return reduction #132686

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions llvm/include/llvm/IR/Function.h
Original file line number Diff line number Diff line change
Expand Up @@ -1048,6 +1048,14 @@ class LLVM_ABI Function : public GlobalObject, public ilist_node<Function> {
void setValueSubclassDataBit(unsigned Bit, bool On);
};

namespace CallingConv {

// TODO: Need similar function for support of argument in position. General
// version on FunctionType + Attributes + CallingConv::ID?
LLVM_READNONE
bool supportsNonVoidReturnType(CallingConv::ID CC);
} // namespace CallingConv

/// Check whether null pointer dereferencing is considered undefined behavior
/// for a given function or an address space.
/// Null pointer access in non-zero address space is not considered undefined.
Expand Down
82 changes: 82 additions & 0 deletions llvm/lib/IR/Function.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1176,3 +1176,85 @@ bool llvm::NullPointerIsDefined(const Function *F, unsigned AS) {

return false;
}

bool llvm::CallingConv::supportsNonVoidReturnType(CallingConv::ID CC) {
switch (CC) {
case CallingConv::C:
case CallingConv::Fast:
case CallingConv::Cold:
case CallingConv::GHC:
case CallingConv::HiPE:
case CallingConv::AnyReg:
case CallingConv::PreserveMost:
case CallingConv::PreserveAll:
case CallingConv::Swift:
case CallingConv::CXX_FAST_TLS:
case CallingConv::Tail:
case CallingConv::CFGuard_Check:
case CallingConv::SwiftTail:
case CallingConv::PreserveNone:
case CallingConv::X86_StdCall:
case CallingConv::X86_FastCall:
case CallingConv::ARM_APCS:
case CallingConv::ARM_AAPCS:
case CallingConv::ARM_AAPCS_VFP:
case CallingConv::MSP430_INTR:
case CallingConv::X86_ThisCall:
case CallingConv::PTX_Device:
case CallingConv::SPIR_FUNC:
case CallingConv::Intel_OCL_BI:
case CallingConv::X86_64_SysV:
case CallingConv::Win64:
case CallingConv::X86_VectorCall:
case CallingConv::DUMMY_HHVM:
case CallingConv::DUMMY_HHVM_C:
case CallingConv::X86_INTR:
case CallingConv::AVR_INTR:
case CallingConv::AVR_SIGNAL:
case CallingConv::AVR_BUILTIN:
return true;
case CallingConv::AMDGPU_KERNEL:
case CallingConv::SPIR_KERNEL:
case CallingConv::AMDGPU_CS_Chain:
case CallingConv::AMDGPU_CS_ChainPreserve:
return false;
case CallingConv::AMDGPU_VS:
case CallingConv::AMDGPU_HS:
case CallingConv::AMDGPU_GS:
case CallingConv::AMDGPU_PS:
case CallingConv::AMDGPU_CS:
case CallingConv::AMDGPU_LS:
case CallingConv::AMDGPU_ES:
case CallingConv::MSP430_BUILTIN:
case CallingConv::AArch64_VectorCall:
case CallingConv::AArch64_SVE_VectorCall:
case CallingConv::WASM_EmscriptenInvoke:
case CallingConv::AMDGPU_Gfx:
case CallingConv::M68k_INTR:
case CallingConv::AArch64_SME_ABI_Support_Routines_PreserveMost_From_X0:
case CallingConv::AArch64_SME_ABI_Support_Routines_PreserveMost_From_X2:
case CallingConv::M68k_RTD:
case CallingConv::GRAAL:
case CallingConv::ARM64EC_Thunk_X64:
case CallingConv::ARM64EC_Thunk_Native:
case CallingConv::RISCV_VectorCall:
case CallingConv::AArch64_SME_ABI_Support_Routines_PreserveMost_From_X1:
case CallingConv::RISCV_VLSCall_32:
case CallingConv::RISCV_VLSCall_64:
case CallingConv::RISCV_VLSCall_128:
case CallingConv::RISCV_VLSCall_256:
case CallingConv::RISCV_VLSCall_512:
case CallingConv::RISCV_VLSCall_1024:
case CallingConv::RISCV_VLSCall_2048:
case CallingConv::RISCV_VLSCall_4096:
case CallingConv::RISCV_VLSCall_8192:
case CallingConv::RISCV_VLSCall_16384:
case CallingConv::RISCV_VLSCall_32768:
case CallingConv::RISCV_VLSCall_65536:
return true;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why are there two separate lists with return true here? What's the difference between them?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was trying to keep this sorted by enum value

default:
return false;
}

llvm_unreachable("covered callingconv switch");
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
; Make sure we don't break on non-callee uses of funtions with a
; non-void return type.

; RUN: llvm-reduce --abort-on-invalid-reduction --delta-passes=instructions-to-return --test FileCheck --test-arg --check-prefix=INTERESTING --test-arg %s --test-arg --input-file %s -o %t
; RUN: FileCheck --check-prefix=RESULT %s < %t

; INTERESTING-LABEL: @interesting(
; INTERESTING: %inttoptr = inttoptr i64

; RESULT-LABEL: define ptr @interesting(i64 %arg) {
; RESULT-NEXT: %inttoptr = inttoptr i64 %arg to ptr
; RESULT-NEXT: ret ptr %inttoptr
define void @interesting(i64 %arg) {
%inttoptr = inttoptr i64 %arg to ptr
%load = load i32, ptr %inttoptr
ret void
}

declare i32 @func(ptr)

; RESULT-LABEL: define i32 @caller() {
; RESULT-NEXT: %call = call i32 @func(ptr @interesting)
; RESULT-NEXT: ret i32 %call
define void @caller() {
%call = call i32 @func(ptr @interesting)
ret void
}
Loading
Loading