[llvm] [AArch64][CodeGen] Fix crash when fptrunc returns fp16 with +nofp attr (PR #81724)

David Green via llvm-commits llvm-commits at lists.llvm.org
Wed Feb 21 06:05:42 PST 2024


================
@@ -0,0 +1,20 @@
+; NOTE: Assertions have been autogenerated by utils/update_llc_test_checks.py UTC_ARGS: --version 4
+; RUN: llc -mtriple=aarch64 -mattr=-fp-armv8 -o - %s | FileCheck %s
+
+define half @f2h(float %a) {
+; CHECK-LABEL: f2h:
+; CHECK:       // %bb.0: // %entry
+; CHECK-NEXT:    str x30, [sp, #-16]! // 8-byte Folded Spill
+; CHECK-NEXT:    .cfi_def_cfa_offset 16
+; CHECK-NEXT:    .cfi_offset w30, -16
+; CHECK-NEXT:    bl __gnu_f2h_ieee
+; CHECK-NEXT:    and w0, w0, #0xffff
+; CHECK-NEXT:    bl __gnu_h2f_ieee
+; CHECK-NEXT:    bl __gnu_f2h_ieee
----------------
davemgreen wrote:

Hmm yeah, perhaps you are right.

I've been doing some sleuthing, and think we need something like #80440. Can you add this:
`bool softPromoteHalfType() const override { return true; }`
and change the code in ReplaceBITCASTResult to instead use
```
if (Subtarget->hasFPARMv8()) {                        
  setOperationAction(ISD::BITCAST, MVT::i16, Custom); 
  setOperationAction(ISD::BITCAST, MVT::f16, Custom); 
  setOperationAction(ISD::BITCAST, MVT::bf16, Custom);
}
```

It might be worth making sure there is a constrained.fptrunc test too.

https://github.com/llvm/llvm-project/pull/81724


More information about the llvm-commits mailing list