[llvm] [AArch64] Fix truncating stores to bf16 when NEON and SVE are unavailable (PR #94437)

Paul Walker via llvm-commits llvm-commits at lists.llvm.org
Wed Jun 5 09:05:12 PDT 2024


================
@@ -6286,6 +6302,14 @@ SDValue AArch64TargetLowering::LowerSTORE(SDValue Op,
     }
   } else if (MemVT == MVT::i128 && StoreNode->isVolatile()) {
     return LowerStore128(Op, DAG);
+  } else if (StoreNode->isTruncatingStore() && MemVT == MVT::bf16) {
+    assert(Subtarget->hasBF16() && "Should have chosen Expand for bf16");
+    SDValue FPRound = DAG.getNode(ISD::FP_ROUND, Dl, MVT::bf16, Value,
+                                  DAG.getIntPtrConstant(0, Dl));
+    SDValue FPRoundBC = DAG.getNode(ISD::BITCAST, Dl, MVT::f16, FPRound);
+    return DAG.getStore(StoreNode->getChain(), Dl, FPRoundBC,
+                        StoreNode->getBasePtr(), StoreNode->getPointerInfo(),
+                        StoreNode->getOriginalAlign());
   } else if (MemVT == MVT::i64x8) {
----------------
paulwalker-arm wrote:

Truncating floating-point store are a bit of a nuisance that I rather not drag into the scalar work.  Just a thought but would changing `hasValidElementTypeForFPTruncStore` to take both the input and output types help? That way you can reject everything related to bfloat.

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


More information about the llvm-commits mailing list