clang tries to use 128-bit function __multi3 on 32-bit target
| 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
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".
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.
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
I was able to replicate this bug in 3.7.1. (Different source. Looks like the 128-bit multiply comes from indvars, btw.)
This was fixed via 789708617d2023dbb343c65120556b2e6a97044d.