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

Modulo operation fails on integers of bitwidth greater than 128 bits #1534

Open
kristate opened this Issue Sep 17, 2018 · 4 comments

Comments

Projects
None yet
2 participants
@kristate
Contributor

kristate commented Sep 17, 2018

test "mod129" {
    const base = 10;
    var a: @IntType(false, 129) = 0;
    const digit = a % base;
}

results in compiler error:

LLVM ERROR: Unsupported library call operation!

#1533 is related.

@kristate

This comment has been minimized.

Contributor

kristate commented Sep 17, 2018

backtrace:

(lldb) bt
* thread #1, queue = 'com.apple.main-thread', stop reason = breakpoint 1.3
  * frame #0: 0x0000000102474cba zig`llvm::report_fatal_error(char const*, bool)
    frame #1: 0x0000000101bb5f95 zig`llvm::TargetLowering::makeLibCall(llvm::SelectionDAG&, llvm::RTLIB::Libcall, llvm::EVT, llvm::ArrayRef<llvm::SDValue>, bool, llvm::SDLoc const&, bool, bool) const + 1445
    frame #2: 0x0000000101afba28 zig`llvm::DAGTypeLegalizer::ExpandIntRes_UREM(llvm::SDNode*, llvm::SDValue&, llvm::SDValue&) + 400
    frame #3: 0x0000000101af6dd8 zig`llvm::DAGTypeLegalizer::ExpandIntegerResult(llvm::SDNode*, unsigned int) + 1524
    frame #4: 0x0000000101b072e5 zig`llvm::DAGTypeLegalizer::run() + 963
    frame #5: 0x0000000101b0a853 zig`llvm::SelectionDAG::LegalizeTypes() + 55
    frame #6: 0x0000000101ba6140 zig`llvm::SelectionDAGISel::CodeGenAndEmitDAG() + 354
    frame #7: 0x0000000101ba53e2 zig`llvm::SelectionDAGISel::SelectAllBasicBlocks(llvm::Function const&) + 5390
    frame #8: 0x0000000101ba364e zig`llvm::SelectionDAGISel::runOnMachineFunction(llvm::MachineFunction&) + 1512
    frame #9: 0x000000010193e6f8 zig`(anonymous namespace)::X86DAGToDAGISel::runOnMachineFunction(llvm::MachineFunction&) + 20
    frame #10: 0x0000000101d0ad8f zig`llvm::MachineFunctionPass::runOnFunction(llvm::Function&) + 113
    frame #11: 0x00000001023f71a4 zig`llvm::FPPassManager::runOnFunction(llvm::Function&) + 276
    frame #12: 0x00000001023f7369 zig`llvm::FPPassManager::runOnModule(llvm::Module&) + 49
    frame #13: 0x00000001023f7695 zig`llvm::legacy::PassManagerImpl::run(llvm::Module&) + 579
    frame #14: 0x00000001001059c5 zig`::ZigLLVMTargetMachineEmitToFile(targ_machine_ref=0x0000000105418c70, module_ref=0x00000001054173e0, filename="zig-cache/test.o", output_type=ZigLLVM_EmitBinary, error_message=0x00007ffeefbfefd0, is_debug=true, is_small=false, time_report=false) at zig_llvm.cpp:181
    frame #15: 0x000000010003a608 zig`zig_llvm_emit_output(g=0x000000010580c600) at codegen.cpp:6408
    frame #16: 0x0000000100037cb3 zig`codegen_build_and_link(g=0x000000010580c600) at codegen.cpp:8231
    frame #17: 0x00000001000cf2d1 zig`main(argc=3, argv=0x00007ffeefbff8d8) at main.cpp:978
    frame #18: 0x00007fff5b6e1015 libdyld.dylib`start + 1
    frame #19: 0x00007fff5b6e1015 libdyld.dylib`start + 1
@kristate

This comment has been minimized.

Contributor

kristate commented Sep 17, 2018

Hmm, llvm does not support urem and friends on integers with bitwidth > 128:

urem_test.ll:

define i256 @urem_test(i256 %a) {
  %1 = urem i256 %a, %a
  ret i256 %1
}

llc urem_test.ll -march=x86-64 -o urem_test-x86-64.s returns:

LLVM ERROR: Unsupported library call operation!

@ghost

This comment has been minimized.

ghost commented Sep 17, 2018

very similar to #1485

@andrewrk andrewrk added this to the 0.4.0 milestone Sep 17, 2018

@andrewrk

This comment has been minimized.

Member

andrewrk commented Sep 17, 2018

The short answer to this and #1485 is that we need to send a patch to LLVM to make it emit library calls for this even though the scope of those library calls is outside of the standardized compiler-rt.

@kristate kristate changed the title from modulus operation fails on integers of bitwidth greater than 128 bits to Modulo operation fails on integers of bitwidth greater than 128 bits Sep 17, 2018

@andrewrk andrewrk modified the milestones: 0.4.0, 0.5.0 Sep 28, 2018

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment