Skip to content

[x86]: Cannot select: constant:i128<0> for llvm.maximum.f128Β #139381

Description

@Urgau

I'm seeing an error when trying to use llvm.minimum.f128 and llvm.maximum.f128 on x86.

; Function Attrs: mustprogress nofree nosync nounwind nonlazybind readnone uwtable willreturn
define fp128 @call_maximum_fp128_x86(fp128 %x, fp128 %y) unnamed_addr #0 {
start:
  %0 = tail call fp128 @llvm.maximum.f128(fp128 %x, fp128 %y) #2
  ret fp128 %0
}

; Function Attrs: mustprogress nofree nosync nounwind readnone speculatable willreturn
declare fp128 @llvm.maximum.f128(fp128, fp128)
LLVM ERROR: Cannot select: 0x3ade0080: i8 = setcc 0x3addc768, Constant:i128<0>, seteq:ch
  0x3addc768: i128 = bitcast 0x3addbe08
    0x3addbe08: f128,ch = CopyFromReg 0x3ad783c0, Register:f128 %1
      0x3addbd90: f128 = Register %1
  0x3addfdb0: i128 = Constant<0>
In function: call_maximum_fp128_x86
PLEASE submit a bug report to https://github.com/llvm/llvm-project/issues/ and include the crash backtrace.
Stack dump:
0.	Program arguments: /opt/compiler-explorer/clang-trunk/bin/llc -o /app/output.s -x86-asm-syntax=intel <source>
1.	Running pass 'Function Pass Manager' on module '<source>'.
2.	Running pass 'X86 DAG->DAG Instruction Selection' on function '@call_maximum_fp128_x86'
 #0 0x0000000003b49548 llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) (/opt/compiler-explorer/clang-trunk/bin/llc+0x3b49548)
 #1 0x0000000003b47104 SignalHandler(int, siginfo_t*, void*) Signals.cpp:0:0
 #2 0x00007e645a842520 (/lib/x86_64-linux-gnu/libc.so.6+0x42520)
 #3 0x00007e645a8969fc pthread_kill (/lib/x86_64-linux-gnu/libc.so.6+0x969fc)
 #4 0x00007e645a842476 gsignal (/lib/x86_64-linux-gnu/libc.so.6+0x42476)
 #5 0x00007e645a8287f3 abort (/lib/x86_64-linux-gnu/libc.so.6+0x287f3)
 #6 0x0000000000784592 llvm::UniqueStringSaver::save(llvm::Twine const&) (.cold) StringSaver.cpp:0:0
 #7 0x00000000038f0888 llvm::SelectionDAGISel::CannotYetSelect(llvm::SDNode*) (/opt/compiler-explorer/clang-trunk/bin/llc+0x38f0888)
 #8 0x00000000038f6bf9 llvm::SelectionDAGISel::SelectCodeCommon(llvm::SDNode*, unsigned char const*, unsigned int) (/opt/compiler-explorer/clang-trunk/bin/llc+0x38f6bf9)
 #9 0x0000000001f70c6a (anonymous namespace)::X86DAGToDAGISel::Select(llvm::SDNode*) X86ISelDAGToDAG.cpp:0:0
#10 0x00000000038edd74 llvm::SelectionDAGISel::DoInstructionSelection() (/opt/compiler-explorer/clang-trunk/bin/llc+0x38edd74)
#11 0x00000000038fc882 llvm::SelectionDAGISel::CodeGenAndEmitDAG() (/opt/compiler-explorer/clang-trunk/bin/llc+0x38fc882)
#12 0x00000000038ff1fa llvm::SelectionDAGISel::SelectAllBasicBlocks(llvm::Function const&) (/opt/compiler-explorer/clang-trunk/bin/llc+0x38ff1fa)
#13 0x00000000039010d6 llvm::SelectionDAGISel::runOnMachineFunction(llvm::MachineFunction&) (/opt/compiler-explorer/clang-trunk/bin/llc+0x39010d6)
#14 0x00000000038ed8f1 llvm::SelectionDAGISelLegacy::runOnMachineFunction(llvm::MachineFunction&) (/opt/compiler-explorer/clang-trunk/bin/llc+0x38ed8f1)
#15 0x0000000002bb4a78 llvm::MachineFunctionPass::runOnFunction(llvm::Function&) (.part.0) MachineFunctionPass.cpp:0:0
#16 0x0000000003135322 llvm::FPPassManager::runOnFunction(llvm::Function&) (/opt/compiler-explorer/clang-trunk/bin/llc+0x3135322)
#17 0x00000000031355b1 llvm::FPPassManager::runOnModule(llvm::Module&) (/opt/compiler-explorer/clang-trunk/bin/llc+0x31355b1)
#18 0x0000000003136f19 llvm::legacy::PassManagerImpl::run(llvm::Module&) (/opt/compiler-explorer/clang-trunk/bin/llc+0x3136f19)
#19 0x00000000008bec3f compileModule(char**, llvm::LLVMContext&) llc.cpp:0:0
#20 0x000000000079977e main (/opt/compiler-explorer/clang-trunk/bin/llc+0x79977e)
#21 0x00007e645a829d90 (/lib/x86_64-linux-gnu/libc.so.6+0x29d90)
#22 0x00007e645a829e40 __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x29e40)
#23 0x00000000008b6705 _start (/opt/compiler-explorer/clang-trunk/bin/llc+0x8b6705)
Program terminated with signal: SIGSEGV
Compiler returned: 139

https://godbolt.org/z/z3arKMfjo

Activity

  1. llvmbot commented on May 10, 2025

    @llvmbot
    Member

    @llvm/issue-subscribers-backend-x86

    Author: None (Urgau)

    Details I'm seeing an error when trying to use llvm.minimum.f128 and llvm.maximum.f128 on x86.
    ; Function Attrs: mustprogress nofree nosync nounwind nonlazybind readnone uwtable willreturn
    define fp128 @<!-- -->call_maximum_fp128_x86(fp128 %x, fp128 %y) unnamed_addr #<!-- -->0 {
    start:
      %0 = tail call fp128 @<!-- -->llvm.maximum.f128(fp128 %x, fp128 %y) #<!-- -->2
      ret fp128 %0
    }
    
    ; Function Attrs: mustprogress nofree nosync nounwind readnone speculatable willreturn
    declare fp128 @<!-- -->llvm.maximum.f128(fp128, fp128)
    LLVM ERROR: Cannot select: 0x3ade0080: i8 = setcc 0x3addc768, Constant:i128&lt;0&gt;, seteq:ch
      0x3addc768: i128 = bitcast 0x3addbe08
        0x3addbe08: f128,ch = CopyFromReg 0x3ad783c0, Register:f128 %1
          0x3addbd90: f128 = Register %1
      0x3addfdb0: i128 = Constant&lt;0&gt;
    In function: call_maximum_fp128_x86
    PLEASE submit a bug report to https://github.com/llvm/llvm-project/issues/ and include the crash backtrace.
    Stack dump:
    0.	Program arguments: /opt/compiler-explorer/clang-trunk/bin/llc -o /app/output.s -x86-asm-syntax=intel &lt;source&gt;
    1.	Running pass 'Function Pass Manager' on module '&lt;source&gt;'.
    2.	Running pass 'X86 DAG-&gt;DAG Instruction Selection' on function '@<!-- -->call_maximum_fp128_x86'
     #<!-- -->0 0x0000000003b49548 llvm::sys::PrintStackTrace(llvm::raw_ostream&amp;, int) (/opt/compiler-explorer/clang-trunk/bin/llc+0x3b49548)
     #<!-- -->1 0x0000000003b47104 SignalHandler(int, siginfo_t*, void*) Signals.cpp:0:0
     #<!-- -->2 0x00007e645a842520 (/lib/x86_64-linux-gnu/libc.so.6+0x42520)
     #<!-- -->3 0x00007e645a8969fc pthread_kill (/lib/x86_64-linux-gnu/libc.so.6+0x969fc)
     #<!-- -->4 0x00007e645a842476 gsignal (/lib/x86_64-linux-gnu/libc.so.6+0x42476)
     #<!-- -->5 0x00007e645a8287f3 abort (/lib/x86_64-linux-gnu/libc.so.6+0x287f3)
     #<!-- -->6 0x0000000000784592 llvm::UniqueStringSaver::save(llvm::Twine const&amp;) (.cold) StringSaver.cpp:0:0
     #<!-- -->7 0x00000000038f0888 llvm::SelectionDAGISel::CannotYetSelect(llvm::SDNode*) (/opt/compiler-explorer/clang-trunk/bin/llc+0x38f0888)
     #<!-- -->8 0x00000000038f6bf9 llvm::SelectionDAGISel::SelectCodeCommon(llvm::SDNode*, unsigned char const*, unsigned int) (/opt/compiler-explorer/clang-trunk/bin/llc+0x38f6bf9)
     #<!-- -->9 0x0000000001f70c6a (anonymous namespace)::X86DAGToDAGISel::Select(llvm::SDNode*) X86ISelDAGToDAG.cpp:0:0
    #<!-- -->10 0x00000000038edd74 llvm::SelectionDAGISel::DoInstructionSelection() (/opt/compiler-explorer/clang-trunk/bin/llc+0x38edd74)
    #<!-- -->11 0x00000000038fc882 llvm::SelectionDAGISel::CodeGenAndEmitDAG() (/opt/compiler-explorer/clang-trunk/bin/llc+0x38fc882)
    #<!-- -->12 0x00000000038ff1fa llvm::SelectionDAGISel::SelectAllBasicBlocks(llvm::Function const&amp;) (/opt/compiler-explorer/clang-trunk/bin/llc+0x38ff1fa)
    #<!-- -->13 0x00000000039010d6 llvm::SelectionDAGISel::runOnMachineFunction(llvm::MachineFunction&amp;) (/opt/compiler-explorer/clang-trunk/bin/llc+0x39010d6)
    #<!-- -->14 0x00000000038ed8f1 llvm::SelectionDAGISelLegacy::runOnMachineFunction(llvm::MachineFunction&amp;) (/opt/compiler-explorer/clang-trunk/bin/llc+0x38ed8f1)
    #<!-- -->15 0x0000000002bb4a78 llvm::MachineFunctionPass::runOnFunction(llvm::Function&amp;) (.part.0) MachineFunctionPass.cpp:0:0
    #<!-- -->16 0x0000000003135322 llvm::FPPassManager::runOnFunction(llvm::Function&amp;) (/opt/compiler-explorer/clang-trunk/bin/llc+0x3135322)
    #<!-- -->17 0x00000000031355b1 llvm::FPPassManager::runOnModule(llvm::Module&amp;) (/opt/compiler-explorer/clang-trunk/bin/llc+0x31355b1)
    #<!-- -->18 0x0000000003136f19 llvm::legacy::PassManagerImpl::run(llvm::Module&amp;) (/opt/compiler-explorer/clang-trunk/bin/llc+0x3136f19)
    #<!-- -->19 0x00000000008bec3f compileModule(char**, llvm::LLVMContext&amp;) llc.cpp:0:0
    #<!-- -->20 0x000000000079977e main (/opt/compiler-explorer/clang-trunk/bin/llc+0x79977e)
    #<!-- -->21 0x00007e645a829d90 (/lib/x86_64-linux-gnu/libc.so.6+0x29d90)
    #<!-- -->22 0x00007e645a829e40 __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x29e40)
    #<!-- -->23 0x00000000008b6705 _start (/opt/compiler-explorer/clang-trunk/bin/llc+0x8b6705)
    Program terminated with signal: SIGSEGV
    Compiler returned: 139
    

    https://godbolt.org/z/z3arKMfjo

  2. nikic commented on May 28, 2025

    @nikic
    Contributor

    The problem is that the expansion for llvm.maximum uses is_fpclass, which in turn expands to an illegal i128 type.

    And the reason this doesn't happen with direct uses of llvm.is.fpclass is this most wonderful hack:

    // If ISD::IS_FPCLASS should be expanded, do it right now, because the
    // expansion can use illegal types. Making expansion early allows
    // legalizing these types prior to selection.
    if (!TLI.isOperationLegal(ISD::IS_FPCLASS, ArgVT) &&
    !TLI.isOperationCustom(ISD::IS_FPCLASS, ArgVT)) {
    SDValue Result = TLI.expandIS_FPCLASS(DestVT, Op, Test, Flags, sdl, DAG);
    setValue(&I, Result);
    return;
    }

  3. nikic commented on May 28, 2025

    @nikic
    Contributor

    So the IS_FPCLASS usage in

    SDValue LCmp = DAG.getSelect(
    DL, VT, DAG.getNode(ISD::IS_FPCLASS, DL, CCVT, LHS, TestZero), LHS,
    MinMax, Flags);
    SDValue RCmp = DAG.getSelect(
    DL, VT, DAG.getNode(ISD::IS_FPCLASS, DL, CCVT, RHS, TestZero), RHS,
    LCmp, Flags);
    is over-kill, as that code really only needs to distinguish the sign bit.

    Doing that is still tricky though, because we can't use a plain bitcast, we have to cast through stack temporary. It looks like legalization has a helper for this use case here:

    void SelectionDAGLegalize::getSignAsIntValue(FloatSignAsInt &State,

    Of course, the code this will generate is very bad.

  4. self-assigned this
    on May 30, 2025
  5. reopened this on Jun 4, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

crashPrefer [crash-on-valid] or [crash-on-invalid]llvm:SelectionDAGSelectionDAGISel as well

Type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions