llvm-project icon indicating copy to clipboard operation
llvm-project copied to clipboard

clang tries to use 128-bit function __multi3 on 32-bit target

Open llvmbot opened this issue 12 years ago • 5 comments

Bugzilla Link 20871
Version trunk
OS Linux
Attachments The C source file that triggers the bug, Preprocessed source, Run script
Reporter LLVM Bugzilla Contributor
CC @topperc,@DMG862,@koutheir,@RKSimon,@riyazvp,@smithp35,@rotateright,@vchuravy

Extended Description

When I try to compile a certain short C-file with clang for a 32-bit i386 target with optimization, I get this linker error: /tmp/addup-b0948d.o:/home/tor/c/addup.c:function addup: error: undefined reference to '__multi3'

As I understand it, __multi3 is a 128-bit function, and not available on 32-bit i386. The C source does not use and 128-bit types, only 64-bit.

With the versions of clang-3.4 and 3.5 in the Ubuntu repositories, clang segfaults instead. Reported here: https://bugs.launchpad.net/ubuntu/+source/llvm-toolchain-snapshot/+bug/1365701

llvmbot avatar Sep 06 '14 23:09 llvmbot

This issue also happens when targeting ARM in 32-bits mode.

It can be fixed, similarly to the x86 fix, by calling setLibcallName(RTLIB::MUL_I128, nullptr) inside ARMTargetLowering::ARMTargetLowering(const TargetMachine &TM, const ARMSubtarget &STI) in the file "llvm/lib/Target/ARM/ARMISelLowering.cpp".

koutheir avatar Jun 03 '21 22:06 koutheir

The changes in https://reviews.llvm.org/D38668 will prevent this issue from manifesting as a using __multi3 on x86. However, one might want to independently look at why licm and/or indvars produces a i65 mul (that gets promoted to i128) for the reduced test submitted by Eric. Generating large multiply instructions on some platforms may lead to less efficient code.

riyazvp avatar Oct 18 '17 19:10 riyazvp

Reduced bitcode test that emits __multi3 even though target is i386 I'm able to get a call to __multi3 from this test using:

opt -O2 reduce.bc -o file2 llc file2 -o file3 grep __multi3 file3

    movl    $0, 16(%esp)
    movl    $0, 12(%esp)
    calll   __multi3   ;<-- on a 32-bit target?
    subl    $4, %esp
    movl    76(%esp), %eax

llvmbot avatar Feb 05 '16 19:02 llvmbot

I was able to replicate this bug in 3.7.1. (Different source. Looks like the 128-bit multiply comes from indvars, btw.)

llvmbot avatar Feb 04 '16 21:02 llvmbot

This was fixed via 789708617d2023dbb343c65120556b2e6a97044d.

DimitryAndric avatar Feb 11 '22 16:02 DimitryAndric