Skip to content

Commit c2551c1

Browse files
committed
[GlobalISel] Remove scalar src from non-sequential fadd/fmul reductions.
It's probably better to split these into separate G_FADD/G_FMUL + G_VECREDUCE operations in the translator rather than carrying the scalar around. The majority of the time it'll get simplified away as the scalars are probably identity values. Differential Revision: https://reviews.llvm.org/D89150
1 parent edbdea7 commit c2551c1

File tree

4 files changed

+15
-24
lines changed

4 files changed

+15
-24
lines changed

llvm/include/llvm/Target/GenericOpcodes.td

+6-15
Original file line numberDiff line numberDiff line change
@@ -1265,35 +1265,26 @@ def G_SHUFFLE_VECTOR: GenericInstruction {
12651265
// Vector reductions
12661266
//------------------------------------------------------------------------------
12671267

1268-
def G_VECREDUCE_SEQ_FADD : GenericInstruction {
1269-
let OutOperandList = (outs type0:$dst);
1270-
let InOperandList = (ins type1:$acc, type2:$v);
1271-
let hasSideEffects = 0;
1272-
}
1273-
1274-
def G_VECREDUCE_SEQ_FMUL : GenericInstruction {
1268+
class VectorReduction : GenericInstruction {
12751269
let OutOperandList = (outs type0:$dst);
1276-
let InOperandList = (ins type1:$acc, type2:$v);
1270+
let InOperandList = (ins type1:$v);
12771271
let hasSideEffects = 0;
12781272
}
12791273

1280-
def G_VECREDUCE_FADD : GenericInstruction {
1274+
def G_VECREDUCE_SEQ_FADD : GenericInstruction {
12811275
let OutOperandList = (outs type0:$dst);
12821276
let InOperandList = (ins type1:$acc, type2:$v);
12831277
let hasSideEffects = 0;
12841278
}
12851279

1286-
def G_VECREDUCE_FMUL : GenericInstruction {
1280+
def G_VECREDUCE_SEQ_FMUL : GenericInstruction {
12871281
let OutOperandList = (outs type0:$dst);
12881282
let InOperandList = (ins type1:$acc, type2:$v);
12891283
let hasSideEffects = 0;
12901284
}
12911285

1292-
class VectorReduction : GenericInstruction {
1293-
let OutOperandList = (outs type0:$dst);
1294-
let InOperandList = (ins type1:$v);
1295-
let hasSideEffects = 0;
1296-
}
1286+
def G_VECREDUCE_FADD : VectorReduction;
1287+
def G_VECREDUCE_FMUL : VectorReduction;
12971288

12981289
def G_VECREDUCE_FMAX : VectorReduction;
12991290
def G_VECREDUCE_FMIN : VectorReduction;

llvm/lib/CodeGen/MachineVerifier.cpp

+5-5
Original file line numberDiff line numberDiff line change
@@ -1489,20 +1489,20 @@ void MachineVerifier::verifyPreISelGenericInstruction(const MachineInstr *MI) {
14891489
break;
14901490
}
14911491
case TargetOpcode::G_VECREDUCE_SEQ_FADD:
1492-
case TargetOpcode::G_VECREDUCE_SEQ_FMUL:
1493-
case TargetOpcode::G_VECREDUCE_FADD:
1494-
case TargetOpcode::G_VECREDUCE_FMUL: {
1492+
case TargetOpcode::G_VECREDUCE_SEQ_FMUL: {
14951493
LLT DstTy = MRI->getType(MI->getOperand(0).getReg());
14961494
LLT Src1Ty = MRI->getType(MI->getOperand(1).getReg());
14971495
LLT Src2Ty = MRI->getType(MI->getOperand(2).getReg());
14981496
if (!DstTy.isScalar())
14991497
report("Vector reduction requires a scalar destination type", MI);
15001498
if (!Src1Ty.isScalar())
1501-
report("FADD/FMUL vector reduction requires a scalar 1st operand", MI);
1499+
report("Sequential FADD/FMUL vector reduction requires a scalar 1st operand", MI);
15021500
if (!Src2Ty.isVector())
1503-
report("FADD/FMUL vector reduction must have a vector 2nd operand", MI);
1501+
report("Sequential FADD/FMUL vector reduction must have a vector 2nd operand", MI);
15041502
break;
15051503
}
1504+
case TargetOpcode::G_VECREDUCE_FADD:
1505+
case TargetOpcode::G_VECREDUCE_FMUL:
15061506
case TargetOpcode::G_VECREDUCE_FMAX:
15071507
case TargetOpcode::G_VECREDUCE_FMIN:
15081508
case TargetOpcode::G_VECREDUCE_ADD:

llvm/test/CodeGen/AArch64/GlobalISel/legalizer-info-validation.mir

+2-2
Original file line numberDiff line numberDiff line change
@@ -619,10 +619,10 @@
619619
# DEBUG-NEXT: G_VECREDUCE_SEQ_FMUL (opcode {{[0-9]+}}): 3 type indices, 0 imm indices
620620
# DEBUG-NEXT: .. type index coverage check SKIPPED: no rules defined
621621
# DEBUG-NEXT: .. imm index coverage check SKIPPED: no rules defined
622-
# DEBUG-NEXT: G_VECREDUCE_FADD (opcode {{[0-9]+}}): 3 type indices, 0 imm indices
622+
# DEBUG-NEXT: G_VECREDUCE_FADD (opcode {{[0-9]+}}): 2 type indices, 0 imm indices
623623
# DEBUG-NEXT: .. type index coverage check SKIPPED: no rules defined
624624
# DEBUG-NEXT: .. imm index coverage check SKIPPED: no rules defined
625-
# DEBUG-NEXT: G_VECREDUCE_FMUL (opcode {{[0-9]+}}): 3 type indices, 0 imm indices
625+
# DEBUG-NEXT: G_VECREDUCE_FMUL (opcode {{[0-9]+}}): 2 type indices, 0 imm indices
626626
# DEBUG-NEXT: .. type index coverage check SKIPPED: no rules defined
627627
# DEBUG-NEXT: .. imm index coverage check SKIPPED: no rules defined
628628
# DEBUG-NEXT: G_VECREDUCE_FMAX (opcode {{[0-9]+}}): 2 type indices, 0 imm indices

llvm/test/MachineVerifier/test_vector_reductions.mir

+2-2
Original file line numberDiff line numberDiff line change
@@ -25,10 +25,10 @@ body: |
2525
; CHECK: Bad machine code: Vector reduction requires a scalar destination type
2626
2727
%dst:_(s64) = G_VECREDUCE_SEQ_FADD %vec_v2s64, %vec_v2s64
28-
; CHECK: Bad machine code: FADD/FMUL vector reduction requires a scalar 1st operand
28+
; CHECK: Bad machine code: Sequential FADD/FMUL vector reduction requires a scalar 1st operand
2929
3030
%dst:_(s64) = G_VECREDUCE_SEQ_FADD %scalar_s64, %scalar_s64
31-
; CHECK: Bad machine code: FADD/FMUL vector reduction must have a vector 2nd operand
31+
; CHECK: Bad machine code: Sequential FADD/FMUL vector reduction must have a vector 2nd operand
3232
3333
%dst2:_(s64) = G_VECREDUCE_MUL %scalar_s64
3434
; CHECK: Bad machine code: Vector reduction requires vector source

0 commit comments

Comments
 (0)