[llvm] [AArch64] missed fold vector fptoui(fdiv(uitofp(x), uitofp(y))) or fptosi(fdiv(sitofp(x), sitofp(y))) into udiv(x, y) or sdiv(x, y) for sve (PR #215146)
via llvm-commits
llvm-commits at lists.llvm.org
Sun Aug 9 20:33:54 PDT 2026
================
@@ -31167,14 +31167,46 @@ static SDValue performPredicateLoadCombine(SDNode *N,
DAG.makeEquivalentMemoryOrdering(Load, LoadPred);
return LoadPred;
}
+static SDValue performFPToIntToDivCombine(SDNode *N, SelectionDAG &DAG) {
+ unsigned Opc = N->getOpcode();
+ bool IsSigned = (Opc == ISD::FP_TO_SINT);
+
+ SDValue FDiv = N->getOperand(0);
+ if (FDiv.getOpcode() != ISD::FDIV)
+ return SDValue();
+
+ EVT IntVT = N->getValueType(0);
+ EVT FPVT = FDiv.getValueType();
+
+ if (IntVT.getVectorElementType() != MVT::i32 ||
+ FPVT.getVectorElementType() != MVT::f64)
+ return SDValue();
+
+ unsigned CastOpc = IsSigned ? ISD::SINT_TO_FP : ISD::UINT_TO_FP;
+ SDValue Op0 = FDiv.getOperand(0);
+ SDValue Op1 = FDiv.getOperand(1);
+ if (Op0.getOpcode() != CastOpc || Op1.getOpcode() != CastOpc)
+ return SDValue();
+
+ if (Op0.getOperand(0).getValueType() != IntVT ||
+ Op1.getOperand(0).getValueType() != IntVT)
+ return SDValue();
+
+ unsigned DivOpc = IsSigned ? ISD::SDIV : ISD::UDIV;
+ return DAG.getNode(DivOpc, SDLoc(N), IntVT, Op0.getOperand(0),
----------------
Andarwinux wrote:
https://support.arm.com/documentation/ddi0487/mc/-Part-C-The-AArch64-Instruction-Set/-Chapter-C3-A64-Instruction-Set-Overview/-C3-7-Data-processing---register/-C3-7-10-Multiply-and-divide
>If a signed integer division (INT_MIN / -1) is performed where INT_MIN is the most negative integer value representable in the selected register size, then the result overflows the signed integer range. No indication of this overflow is produced and the result that is written to the destination register is INT_MIN.
https://llvm.org/docs/LangRef.html#fptoui-to-instruction
>The ‘fptoui’ instruction converts its [floating-point](https://llvm.org/docs/LangRef.html#t-floating) operand into the nearest (rounding towards zero) unsigned integer value. If the value cannot fit in ty2, the result is a [poison value](https://llvm.org/docs/LangRef.html#poisonvalues).
>The ‘fptosi’ instruction converts its [floating-point](https://llvm.org/docs/LangRef.html#t-floating) operand into the nearest (rounding towards zero) signed integer value. If the value cannot fit in ty2, the result is a [poison value](https://llvm.org/docs/LangRef.html#poisonvalues).
It's still just return a poison.
https://github.com/llvm/llvm-project/pull/215146
More information about the llvm-commits
mailing list