Skip to content

Commit e08422d

Browse files
committed
[ISel] Commute FMUL and inserting zero into vector lane
1 parent 93a6be0 commit e08422d

File tree

2 files changed

+33
-1
lines changed

2 files changed

+33
-1
lines changed

llvm/lib/Target/AArch64/AArch64ISelLowering.cpp

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26268,11 +26268,43 @@ static SDValue removeRedundantInsertVectorElt(SDNode *N) {
2626826268
return ExtractVec;
2626926269
}
2627026270

26271+
static SDValue commuteInsertVectorEltFMul(SDNode *N, SelectionDAG &DAG) {
26272+
assert(N->getOpcode() == ISD::INSERT_VECTOR_ELT && "Unexpected node!");
26273+
SDValue InsertVec = N->getOperand(0);
26274+
SDValue InsertVal = N->getOperand(1);
26275+
SDValue InsertIdx = N->getOperand(2);
26276+
26277+
// Only handle constant 0 insertion...
26278+
if (!(isNullConstant(InsertVal) || isNullFPConstant(InsertVal)))
26279+
return SDValue();
26280+
// ... into the result of an FMUL.
26281+
if (InsertVec.getOpcode() != ISD::FMUL)
26282+
return SDValue();
26283+
26284+
// Insert into the operand of FMUL instead.
26285+
SDValue FMulOp = InsertVec.getOperand(0);
26286+
26287+
if (!InsertVec.hasOneUse() || !FMulOp.hasOneUse())
26288+
return SDValue();
26289+
26290+
SDValue InsertOp =
26291+
DAG.getNode(ISD::INSERT_VECTOR_ELT, SDLoc(N), FMulOp.getValueType(),
26292+
FMulOp, InsertVal, InsertIdx);
26293+
SDValue FMul =
26294+
DAG.getNode(ISD::FMUL, SDLoc(InsertVec), InsertVec.getValueType(),
26295+
InsertOp, InsertVec.getOperand(1));
26296+
DAG.ReplaceAllUsesWith(N, &FMul);
26297+
return FMul;
26298+
}
26299+
2627126300
static SDValue
2627226301
performInsertVectorEltCombine(SDNode *N, TargetLowering::DAGCombinerInfo &DCI) {
2627326302
if (SDValue Res = removeRedundantInsertVectorElt(N))
2627426303
return Res;
2627526304

26305+
if (SDValue Res = commuteInsertVectorEltFMul(N, DCI.DAG))
26306+
return Res;
26307+
2627626308
return performPostLD1Combine(N, DCI, true);
2627726309
}
2627826310

llvm/test/CodeGen/AArch64/arm64-vmul.ll

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1189,8 +1189,8 @@ define double @fmul_lane_d(double %A, <2 x double> %vec) nounwind {
11891189
define <4 x float> @fmul_insert_zero(<4 x float> %A, <4 x float> %B) {
11901190
; CHECK-LABEL: fmul_insert_zero:
11911191
; CHECK: // %bb.0:
1192-
; CHECK-NEXT: fmul.4s v0, v0, v1
11931192
; CHECK-NEXT: mov.s v0[3], wzr
1193+
; CHECK-NEXT: fmul.4s v0, v0, v1
11941194
; CHECK-NEXT: ret
11951195
%mul = fmul <4 x float> %A, %B
11961196
%mul_set_lane = insertelement <4 x float> %mul, float 0.000000e+00, i64 3

0 commit comments

Comments
 (0)