Skip to content

Strict floating point is incompatible with SPE #49729

@vit9696

Description

@vit9696
Bugzilla Link 50385
Resolution FIXED
Resolved on Jul 07, 2021 01:24
Version 12.0
OS All
Blocks #48661
CC @chmeeedalf,@ecnelises,@hfinkel,@nemanjai,@pattop,@tstellar
Fixed by commit(s) 5c18d11 6279fd1

Extended Description

Enabling strict floating point support on PowerPC[1] caused a regression with SPE-enabled targets making them crash when compiling SPE-enabled code without the ability to avoid it. Example:

#define ZEROINFNAN (0x7ff-0x3ff-52-1)

struct num { unsigned long long m; int e; int sign; };

double func(double x, double y, double z)
{
#pragma STDC FENV_ACCESS ON

struct num nx = (struct num){0,0,0}; if (nx.e >= ZEROINFNAN)	return x*y + z; return 0; 

}

$ clang -o fma.o -c -target powerpc-gnu-linux-eabi -mspe fma.c
fatal error: error in backend: Cannot select: 0x7f8c58889e88: f64,ch = strict_fadd 0x7f8c3fd05968, 0x7f8c5888a1c8, 0x7f8c58889f58
0x7f8c5888a1c8: f64,ch = strict_fmul 0x7f8c3fd05968, 0x7f8c5888a0f8, 0x7f8c5888bc00
0x7f8c5888a0f8: f64,ch = load<(dereferenceable load 8 from %ir.5)> 0x7f8c3fd05968, FrameIndex:i32<1>, undef:i32
0x7f8c5888be08: i32 = FrameIndex<1>
0x7f8c5888bfa8: i32 = undef
0x7f8c5888bc00: f64,ch = load<(dereferenceable load 8 from %ir.6)> 0x7f8c3fd05968, FrameIndex:i32<2>, undef:i32
0x7f8c5888a028: i32 = FrameIndex<2>
0x7f8c5888bfa8: i32 = undef
0x7f8c58889f58: f64,ch = load<(dereferenceable load 8 from %ir.7)> 0x7f8c3fd05968, FrameIndex:i32<3>, undef:i32
0x7f8c5888bc68: i32 = FrameIndex<3>
0x7f8c5888bfa8: i32 = undef
In function: func
PLEASE submit a bug report to https://bugs.llvm.org/ and include the crash backtrace, preprocessed source, and associated run script.
Stack dump:
0. Program arguments: clang -o fma.o -c -target powerpc-gnu-linux-eabi -mspe fma.c

  1. parser at end of file
  2. Code generation
  3. Running pass 'Function Pass Manager' on module 'fma.c'.
  4. Running pass 'PowerPC DAG->DAG Pattern Instruction Selection' on function '@func'
    Stack dump without symbol names (ensure you have llvm-symbolizer in your PATH or set the environment var LLVM_SYMBOLIZER_PATH to point to it):
    0 clang 0x000000010cb986ba llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) + 43
    1 clang 0x000000010cb981a7 llvm::sys::CleanupOnSignal(unsigned long) + 184
    2 clang 0x000000010cb1ad59 (anonymous namespace)::CrashRecoveryContextImpl::HandleCrash(int, unsigned long) + 97
    3 clang 0x000000010cb1acf6 llvm::CrashRecoveryContext::HandleExit(int) + 14
    4 clang 0x000000010cb95c7e llvm::sys::Process::Exit(int, bool) + 44
    5 clang 0x000000010bb97632 std::__1::basic_string<char, std::__1::char_traits, std::__1::allocator >::basic_stringstd::nullptr_t(char const*) + 0
    6 clang 0x000000010cb21088 llvm::report_fatal_error(llvm::Twine const&, bool) + 293
    7 clang 0x000000010cb210bf llvm::report_fatal_error(llvm::StringRef, bool) + 0
    8 clang 0x000000010d4b9af8 llvm::SelectionDAGISel::isOrEquivalentToAdd(llvm::SDNode const*) const + 0
    9 clang 0x000000010d4b9294 llvm::SelectionDAGISel::SelectCodeCommon(llvm::SDNode*, unsigned char const*, unsigned int) + 12192
    10 clang 0x000000010bf2ce92 (anonymous namespace)::PPCDAGToDAGISel::Select(llvm::SDNode*) + 20582
    11 clang 0x000000010d4b38b5 llvm::SelectionDAGISel::DoInstructionSelection() + 341
    12 clang 0x000000010d4b3154 llvm::SelectionDAGISel::CodeGenAndEmitDAG() + 1500
    13 clang 0x000000010d4b273b llvm::SelectionDAGISel::SelectAllBasicBlocks(llvm::Function const&) + 3605
    14 clang 0x000000010d4b1004 llvm::SelectionDAGISel::runOnMachineFunction(llvm::MachineFunction&) + 1774
    15 clang 0x000000010bf246f8 (anonymous namespace)::PPCDAGToDAGISel::runOnMachineFunction(llvm::MachineFunction&) + 58
    16 clang 0x000000010c49680f llvm::MachineFunctionPass::runOnFunction(llvm::Function&) + 255
    17 clang 0x000000010c6c59ba llvm::FPPassManager::runOnFunction(llvm::Function&) + 512
    18 clang 0x000000010c6c936e llvm::FPPassManager::runOnModule(llvm::Module&) + 52
    19 clang 0x000000010c6c5de1 llvm::legacy::PassManagerImpl::run(llvm::Module&) + 649
    20 clang 0x000000010cd38695 clang::EmitBackendOutput(clang::DiagnosticsEngine&, clang::HeaderSearchOptions const&, clang::CodeGenOptions const&, clang::TargetOptions const&, clang::LangOptions const&, llvm::DataLayout const&, llvm::Module*, clang::BackendAction, std::__1::unique_ptr<llvm::raw_pwrite_stream, std::__1::default_deletellvm::raw_pwrite_stream >) + 8829
    21 clang 0x000000010cf42470 clang::BackendConsumer::HandleTranslationUnit(clang::ASTContext&) + 1080
    22 clang 0x000000010dac2324 clang::ParseAST(clang::Sema&, bool, bool) + 543
    23 clang 0x000000010d122ce7 clang::FrontendAction::Execute() + 75
    24 clang 0x000000010d0dc880 clang::CompilerInstance::ExecuteAction(clang::FrontendAction&) + 1516
    25 clang 0x000000010d17091d clang::ExecuteCompilerInvocation(clang::CompilerInstance*) + 1025
    26 clang 0x000000010bb972fc cc1_main(llvm::ArrayRef<char const*>, char const*, void*) + 1690
    27 clang 0x000000010bb9642d ExecuteCC1Tool(llvm::SmallVectorImpl<char const*>&) + 331
    28 clang 0x000000010d00d37b void llvm::function_ref<void ()>::callback_fn<clang::driver::CC1Command::Execute(llvm::ArrayRef<llvm::Optionalllvm::StringRef >, std::__1::basic_string<char, std::__1::char_traits, std::__1::allocator >, bool) const::$_1>(long) + 23
    29 clang 0x000000010cb1acd6 llvm::CrashRecoveryContext::RunSafely(llvm::function_ref<void ()>) + 226
    30 clang 0x000000010d00cac2 clang::driver::CC1Command::Execute(llvm::ArrayRef<llvm::Optionalllvm::StringRef >, std::__1::basic_string<char, std::__1::char_traits, std::__1::allocator >, bool) const + 230
    31 clang 0x000000010cff061e clang::driver::Compilation::ExecuteCommand(clang::driver::Command const&, clang::driver::Command const*&) const + 510
    32 clang 0x000000010cff0727 clang::driver::Compilation::ExecuteJobs(clang::driver::JobList const&, llvm::SmallVectorImpl<std::__1::pair<int, clang::driver::Command const*> >&) const + 95
    33 clang 0x000000010cffcd8f clang::driver::Driver::ExecuteCompilation(clang::driver::Compilation&, llvm::SmallVectorImpl<std::__1::pair<int, clang::driver::Command const*> >&) + 213
    34 clang 0x000000010bb960ab main + 7314
    35 libdyld.dylib 0x00007fff205b6f3d start + 1
    clang-12: error: clang frontend command failed with exit code 70 (use -v to see invocation)
    clang version 12.0.0
    Target: powerpc-gnu-linux-eabi
    Thread model: posix
    InstalledDir: /opt/llvm/bin
    clang-12: note: diagnostic msg:

PLEASE ATTACH THE FOLLOWING FILES TO THE BUG REPORT:
Preprocessed source(s) and associated run script(s) are located at:
clang-12: note: diagnostic msg: /var/folders/v8/mhvsdtrj3d97rmymc2218nl80000gn/T/fma-2bbb85.c
clang-12: note: diagnostic msg: /var/folders/v8/mhvsdtrj3d97rmymc2218nl80000gn/T/fma-2bbb85.sh
clang-12: note: diagnostic msg: Crash backtrace is located in
clang-12: note: diagnostic msg: /Users/user/Library/Logs/DiagnosticReports/clang-12__.crash
clang-12: note: diagnostic msg: (choose the .crash file that corresponds to your crash)
clang-12: note: diagnostic msg:


For the time being this can be avoided by the following patch, which I suggest including in 12.0.1 to avoid the regression:

diff --git clang/lib/Basic/Targets/PPC.cpp clang/lib/Basic/Targets/PPC.cpp
index ff09c0fa2..17c1d1606 100644
--- clang/lib/Basic/Targets/PPC.cpp
+++ clang/lib/Basic/Targets/PPC.cpp
@@ -58,6 +58,7 @@ bool PPCTargetInfo::handleTargetFeatures(std::vectorstd::string &Features,
HasPCRelativeMemops = true;
} else if (Feature == "+spe" || Feature == "+efpu2") {
HasSPE = true;

  •  HasStrictFP = false; LongDoubleWidth = LongDoubleAlign = 64; LongDoubleFormat = &llvm::APFloat::IEEEdouble(); 
    } else if (Feature == "-hard-float") {

[1] 8ecc852

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions