Closed tgross35 closed 2 weeks ago
It seems like it is able to do the correct thing if assertions are disabled, this seems to produce the correct result in https://play.rust-lang.org/?version=nightly&mode=debug&edition=2021&gist=1abe8952ee9d287a4f2b31c812e00743.
@llvm/issue-subscribers-backend-x86
Author: Trevor Gross (tgross35)
^ to affirm the labels, this does not seem to crash on aarch64.
RTLIB::getFPLibCall
doesn't support f16
. The problem could arise with many other targets/Opcodes.
What is getFPLibCall
expected to do in these cases? I don't think there are any platforms that would actually have external f16
functions.
Testing some other arches. At least the following seem to work without crash, even though I know some of them have f16 ABI issues:
--mtriple=aarch64-pc-windows-msvc
--mtriple=aarch64-unknown-linux-gnu
--mtriple=arm-unknown-linux-gnueabi
--mtriple=armv7-unknown-linux-gnueabihf
--mtriple=i586-unknown-linux-gnu
--mtriple=i586-unknown-linux-musl
--mtriple=i686-unknown-linux-gnu
--mtriple=loongarch64-unknown-linux-gnu
--mtriple=riscv64-unknown-linux-gnu
--mtriple=powerpc-unknown-linux-gnu
--mtriple=powerpc64-unknown-linux-gnu
--mtriple=powerpc64le-unknown-linux-gnu
aarch64
Legalizing: t5: f16 = fpowi t2, t4
Trying to promote node
Creating new node: t9: f32 = fp_extend t2
Creating new node: t10: f32 = fpowi t9, t4
Creating constant: t11: i64 = TargetConstant<0>
Creating new node: t12: f16 = fp_round t10, TargetConstant:i64<0>
Successfully promoted node
... replacing: t5: f16 = fpowi t2, t4
with: t12: f16 = fp_round t10, TargetConstant:i64<0>
aarch64-pc-windows-msvc
Legalizing: t5: f16 = fpowi t2, t4
Trying to promote node
Creating new node: t9: f32 = fp_extend t2
Creating new node: t10: f32 = fpowi t9, t4
Creating constant: t11: i64 = TargetConstant<0>
Creating new node: t12: f16 = fp_round t10, TargetConstant:i64<0>
Successfully promoted node
... replacing: t5: f16 = fpowi t2, t4
with: t12: f16 = fp_round t10, TargetConstant:i64<0>
aarch64-unknown-linux-gnu
Legalizing: t5: f16 = fpowi t2, t4
Trying to promote node
Creating new node: t9: f32 = fp_extend t2
Creating new node: t10: f32 = fpowi t9, t4
Creating constant: t11: i64 = TargetConstant<0>
Creating new node: t12: f16 = fp_round t10, TargetConstant:i64<0>
Successfully promoted node
... replacing: t5: f16 = fpowi t2, t4
with: t12: f16 = fp_round t10, TargetConstant:i64<0>
i586-unknown-linux-gnu
Legalizing node: t7: f16 = fpowi t13, t5
Analyzing result type: f16
Soft promote half result 0: t7: f16 = fpowi t13, t5
Creating new node: t15: f32 = fp16_to_fp t14
Creating new node: t16: f32 = fpowi t15, t5
Creating new node: t17: i16 = fp_to_fp16 t16
i586-unknown-linux-musl
Legalizing node: t7: f16 = fpowi t13, t5
Analyzing result type: f16
Soft promote half result 0: t7: f16 = fpowi t13, t5
Creating new node: t15: f32 = fp16_to_fp t14
Creating new node: t16: f32 = fpowi t15, t5
Creating new node: t17: i16 = fp_to_fp16 t16
i686-unknown-linux-gnu
Legalizing node: t7: f16 = fpowi t13, t5
Analyzing result type: f16
Soft promote half result 0: t7: f16 = fpowi t13, t5
Creating new node: t15: f32 = fp16_to_fp t14
Creating new node: t16: f32 = fpowi t15, t5
Creating new node: t17: i16 = fp_to_fp16 t16
loongarch64-unknown-linux-gnu
Legalizing node: t8: f16 = fpowi t6, t7
Analyzing result type: f16
Promote float result 0: t8: f16 = fpowi t6, t7
Creating new node: t28: f32 = fpowi t14, t7
riscv64-unknown-linux-gnu
Legalizing node: t8: f16 = fpowi t6, t7
Analyzing result type: f16
Soft promote half result 0: t8: f16 = fpowi t6, t7
Creating new node: t14: f32 = fp16_to_fp t5
Creating new node: t15: f32 = fpowi t14, t7
Creating new node: t16: i16 = fp_to_fp16 t15
x86_64
Assertion failed: LC != RTLIB::UNKNOWN_LIBCALL && "Unexpected fpowi." (/home/v01dxyz/llvm-project/llvm/lib/CodeGen/SelectionDAG/LegalizeDAG.cpp: ConvertNodeToLibcall: 4708)
PLEASE submit a bug report to https://github.com/llvm/llvm-project/issues/ and include the crash backtrace.
Stack dump:
0. Program arguments: /home/v01dxyz/llvm-project/build.indvars_simplify/bin/llc faulty.ll --mtriple=x86_64 -debug -o=/dev/null
1. Running pass 'Function Pass Manager' on module 'faulty.ll'.
2. Running pass 'X86 DAG->DAG Instruction Selection' on function '@test_half_powi'
#0 0x00007f1acfcec809 PrintStackTraceSignalHandler(void*) /home/v01dxyz/llvm-project/llvm/lib/Support/Unix/Signals.inc:798:1
#1 0x00007f1acfce9a7f llvm::sys::RunSignalHandlers() /home/v01dxyz/llvm-project/llvm/lib/Support/Signals.cpp:105:20
#2 0x00007f1acfcebe31 SignalHandler(int) /home/v01dxyz/llvm-project/llvm/lib/Support/Unix/Signals.inc:413:1
#3 0x00007f1adb7789be __restore_rt /builddir/musl-1.1.24/src/signal/x86_64/restore.s:6:0
Legalizing: t5: f16 = fpowi t2, t4
Trying to expand node
Cannot expand node
Trying to convert node to libcall
The following timeout ones with -debug
. I don't know the reason. Nevertheless it's sucessful at legalisation.
arm-unknown-linux-gnueabi
Legalizing: t5: f16 = fpowi t2, t4
Trying to promote node
Creating new node: t9: f32 = fp_extend t2
Creating new node: t10: f32 = fpowi t9, t4
Creating constant: t11: i64 = TargetConstant<0>
Creating new node: t12: f16 = fp_round t10, TargetConstant:i64<0>
Successfully promoted node
... replacing: t5: f16 = fpowi t2, t4
with: t12: f16 = fp_round t10, TargetConstant:i64<0>
armv7-unknown-linux-gnueabihf
Legalizing: t5: f16 = fpowi t2, t4
Trying to promote node
Creating new node: t9: f32 = fp_extend t2
Creating new node: t10: f32 = fpowi t9, t4
Creating constant: t11: i64 = TargetConstant<0>
Creating new node: t12: f16 = fp_round t10, TargetConstant:i64<0>
Successfully promoted node
... replacing: t5: f16 = fpowi t2, t4
with: t12: f16 = fp_round t10, TargetConstant:i64<0>
Normally, f16
is promoted by default if f16
is not a legal type (cf TargetLoweringBase::computeRegisterProperties
). A target with f16
being legal should set an operation action for FPOWI
.
X86
with SSE2
makes f16
legal without doing the latter.
if you try your example llc -mattr=-sse2
, it works (just to prove my point).
f16
without SSE2
has ABI issue, so it's not a valiad case. We have error out this in frontend https://godbolt.org/z/6K3j9n4G4
Source code:
Crash (assertions required):
Link: https://llvm.godbolt.org/z/zhb1bxWK8