Skip to content

Commit 6cd1750

Browse files
committed
[RISCV] Add disjoint or patterns for vwadd[u].vv
DAGCombiner::hoistLogicOpWithSameOpcodeHands will hoist (or disjoint (ext a), (ext b)) -> (ext (or disjoint a, b)) So this adds a pattern to match vwadd[u].vv in this case. We have to teach the combine to preserve the disjoint flag, and add a generic PatFrag for a disjoint or. This is meant to be a follow up to llvm#136677 which would allow us to remove the target hook added there.
1 parent 053451c commit 6cd1750

File tree

4 files changed

+30
-11
lines changed

4 files changed

+30
-11
lines changed

llvm/include/llvm/Target/TargetSelectionDAG.td

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1113,6 +1113,10 @@ def not : PatFrag<(ops node:$in), (xor node:$in, -1)>;
11131113
def vnot : PatFrag<(ops node:$in), (xor node:$in, immAllOnesV)>;
11141114
def ineg : PatFrag<(ops node:$in), (sub 0, node:$in)>;
11151115

1116+
def or_disjoint : PatFrag<(ops node:$x, node:$y), (or node:$x, node:$y), [{
1117+
return N->getFlags().hasDisjoint();
1118+
}]>;
1119+
11161120
def zanyext : PatFrags<(ops node:$op),
11171121
[(zext node:$op),
11181122
(anyext node:$op)]>;

llvm/lib/CodeGen/SelectionDAG/DAGCombiner.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5982,7 +5982,9 @@ SDValue DAGCombiner::hoistLogicOpWithSameOpcodeHands(SDNode *N) {
59825982
LegalTypes && !TLI.isTypeDesirableForOp(LogicOpcode, XVT))
59835983
return SDValue();
59845984
// logic_op (hand_op X), (hand_op Y) --> hand_op (logic_op X, Y)
5985-
SDValue Logic = DAG.getNode(LogicOpcode, DL, XVT, X, Y);
5985+
SDNodeFlags LogicFlags;
5986+
LogicFlags.setDisjoint(N->getFlags().hasDisjoint());
5987+
SDValue Logic = DAG.getNode(LogicOpcode, DL, XVT, X, Y, LogicFlags);
59865988
if (HandOpcode == ISD::SIGN_EXTEND_INREG)
59875989
return DAG.getNode(HandOpcode, DL, VT, Logic, N0.getOperand(1));
59885990
return DAG.getNode(HandOpcode, DL, VT, Logic);

llvm/lib/Target/RISCV/RISCVInstrInfoVSDPatterns.td

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -912,6 +912,25 @@ defm : VPatWidenBinarySDNode_VV_VX_WV_WX<add, sext_oneuse, "PseudoVWADD">;
912912
defm : VPatWidenBinarySDNode_VV_VX_WV_WX<add, zext_oneuse, "PseudoVWADDU">;
913913
defm : VPatWidenBinarySDNode_VV_VX_WV_WX<add, anyext_oneuse, "PseudoVWADDU">;
914914

915+
// DAGCombiner::hoistLogicOpWithSameOpcodeHands may hoist disjoint ors
916+
// to (ext (or disjoint (a, b)))
917+
multiclass VPatWidenOrDisjoint_VV<SDNode extop, string instruction_name> {
918+
foreach vtiToWti = AllWidenableIntVectors in {
919+
defvar vti = vtiToWti.Vti;
920+
defvar wti = vtiToWti.Wti;
921+
let Predicates = !listconcat(GetVTypePredicates<vti>.Predicates,
922+
GetVTypePredicates<wti>.Predicates) in {
923+
def : Pat<(wti.Vector (extop (vti.Vector (or_disjoint vti.RegClass:$rs2, vti.RegClass:$rs1)))),
924+
(!cast<Instruction>(instruction_name#"_VV_"#vti.LMul.MX)
925+
(wti.Vector (IMPLICIT_DEF)), vti.RegClass:$rs2,
926+
vti.RegClass:$rs1, vti.AVL, vti.Log2SEW, TA_MA)>;
927+
}
928+
}
929+
}
930+
defm : VPatWidenOrDisjoint_VV<sext, "PseudoVWADD">;
931+
defm : VPatWidenOrDisjoint_VV<zext, "PseudoVWADDU">;
932+
defm : VPatWidenOrDisjoint_VV<anyext, "PseudoVWADDU">;
933+
915934
defm : VPatWidenBinarySDNode_VV_VX_WV_WX<sub, sext_oneuse, "PseudoVWSUB">;
916935
defm : VPatWidenBinarySDNode_VV_VX_WV_WX<sub, zext_oneuse, "PseudoVWSUBU">;
917936
defm : VPatWidenBinarySDNode_VV_VX_WV_WX<sub, anyext_oneuse, "PseudoVWSUBU">;

llvm/test/CodeGen/RISCV/rvv/vwadd-sdnode.ll

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1417,31 +1417,25 @@ define <vscale x 2 x i32> @vwaddu_vv_disjoint_or_add(<vscale x 2 x i8> %x.i8, <v
14171417
ret <vscale x 2 x i32> %add
14181418
}
14191419

1420-
; TODO: We could select vwaddu.vv, but when both arms of the or are the same
1421-
; DAGCombiner::hoistLogicOpWithSameOpcodeHands moves the zext above the or.
14221420
define <vscale x 2 x i32> @vwaddu_vv_disjoint_or(<vscale x 2 x i16> %x.i16, <vscale x 2 x i16> %y.i16) {
14231421
; CHECK-LABEL: vwaddu_vv_disjoint_or:
14241422
; CHECK: # %bb.0:
14251423
; CHECK-NEXT: vsetvli a0, zero, e16, mf2, ta, ma
1426-
; CHECK-NEXT: vor.vv v9, v8, v9
1427-
; CHECK-NEXT: vsetvli zero, zero, e32, m1, ta, ma
1428-
; CHECK-NEXT: vzext.vf2 v8, v9
1424+
; CHECK-NEXT: vwaddu.vv v10, v8, v9
1425+
; CHECK-NEXT: vmv1r.v v8, v10
14291426
; CHECK-NEXT: ret
14301427
%x.i32 = zext <vscale x 2 x i16> %x.i16 to <vscale x 2 x i32>
14311428
%y.i32 = zext <vscale x 2 x i16> %y.i16 to <vscale x 2 x i32>
14321429
%or = or disjoint <vscale x 2 x i32> %x.i32, %y.i32
14331430
ret <vscale x 2 x i32> %or
14341431
}
14351432

1436-
; TODO: We could select vwadd.vv, but when both arms of the or are the same
1437-
; DAGCombiner::hoistLogicOpWithSameOpcodeHands moves the zext above the or.
14381433
define <vscale x 2 x i32> @vwadd_vv_disjoint_or(<vscale x 2 x i16> %x.i16, <vscale x 2 x i16> %y.i16) {
14391434
; CHECK-LABEL: vwadd_vv_disjoint_or:
14401435
; CHECK: # %bb.0:
14411436
; CHECK-NEXT: vsetvli a0, zero, e16, mf2, ta, ma
1442-
; CHECK-NEXT: vor.vv v9, v8, v9
1443-
; CHECK-NEXT: vsetvli zero, zero, e32, m1, ta, ma
1444-
; CHECK-NEXT: vsext.vf2 v8, v9
1437+
; CHECK-NEXT: vwadd.vv v10, v8, v9
1438+
; CHECK-NEXT: vmv1r.v v8, v10
14451439
; CHECK-NEXT: ret
14461440
%x.i32 = sext <vscale x 2 x i16> %x.i16 to <vscale x 2 x i32>
14471441
%y.i32 = sext <vscale x 2 x i16> %y.i16 to <vscale x 2 x i32>

0 commit comments

Comments
 (0)