Skip to content

Commit af315f7

Browse files
toppercyuxuanchen1997
authored andcommitted
Re-commit "[RISCV] Use Root instead of N throughout the worklist loop in combineBinOp_VLToVWBinOp_VL. (#99416)"
Summary: With correct test update. Original message: We were only checking that the node from the worklist is a supported root. We weren't checking the strategy or any of its operands unless it was the original node. For any other node, we just rechecked the original node's strategy and operands. The effect of this is that we don't do all of the transformations at once. Instead, when there were multiple possible nodes to transform we would only do them as each node was visited by the main DAG combine worklist. The test shows a case where we widened an instruction without removing all of the uses of the vsext. The sext is shared by one node that shares another sext node with the root another node that doesn't share anything with the root. Test Plan: Reviewers: Subscribers: Tasks: Tags: Differential Revision: https://phabricator.intern.facebook.com/D60250791
1 parent 199ffa4 commit af315f7

File tree

2 files changed

+42
-5
lines changed

2 files changed

+42
-5
lines changed

llvm/lib/Target/RISCV/RISCVISelLowering.cpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14998,8 +14998,8 @@ static SDValue combineBinOp_VLToVWBinOp_VL(SDNode *N,
1499814998
if (!NodeExtensionHelper::isSupportedRoot(Root, Subtarget))
1499914999
return SDValue();
1500015000

15001-
NodeExtensionHelper LHS(N, 0, DAG, Subtarget);
15002-
NodeExtensionHelper RHS(N, 1, DAG, Subtarget);
15001+
NodeExtensionHelper LHS(Root, 0, DAG, Subtarget);
15002+
NodeExtensionHelper RHS(Root, 1, DAG, Subtarget);
1500315003
auto AppendUsersIfNeeded = [&Worklist,
1500415004
&Inserted](const NodeExtensionHelper &Op) {
1500515005
if (Op.needToPromoteOtherUsers()) {
@@ -15016,18 +15016,18 @@ static SDValue combineBinOp_VLToVWBinOp_VL(SDNode *N,
1501615016
return SDValue();
1501715017

1501815018
SmallVector<NodeExtensionHelper::CombineToTry> FoldingStrategies =
15019-
NodeExtensionHelper::getSupportedFoldings(N);
15019+
NodeExtensionHelper::getSupportedFoldings(Root);
1502015020

1502115021
assert(!FoldingStrategies.empty() && "Nothing to be folded");
1502215022
bool Matched = false;
1502315023
for (int Attempt = 0;
15024-
(Attempt != 1 + NodeExtensionHelper::isCommutative(N)) && !Matched;
15024+
(Attempt != 1 + NodeExtensionHelper::isCommutative(Root)) && !Matched;
1502515025
++Attempt) {
1502615026

1502715027
for (NodeExtensionHelper::CombineToTry FoldingStrategy :
1502815028
FoldingStrategies) {
1502915029
std::optional<CombineResult> Res =
15030-
FoldingStrategy(N, LHS, RHS, DAG, Subtarget);
15030+
FoldingStrategy(Root, LHS, RHS, DAG, Subtarget);
1503115031
if (Res) {
1503215032
Matched = true;
1503315033
CombinesToApply.push_back(*Res);

llvm/test/CodeGen/RISCV/rvv/fixed-vectors-vwmul.ll

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -882,3 +882,40 @@ define <2 x i64> @vwmul_vx_v2i64_i64(ptr %x, ptr %y) {
882882
%g = mul <2 x i64> %e, %f
883883
ret <2 x i64> %g
884884
}
885+
886+
define <2 x i16> @vwmul_v2i16_multiuse(ptr %x, ptr %y, ptr %z, ptr %w) {
887+
; CHECK-LABEL: vwmul_v2i16_multiuse:
888+
; CHECK: # %bb.0:
889+
; CHECK-NEXT: vsetivli zero, 2, e16, mf4, ta, ma
890+
; CHECK-NEXT: vle8.v v8, (a0)
891+
; CHECK-NEXT: vle8.v v9, (a1)
892+
; CHECK-NEXT: vle8.v v10, (a2)
893+
; CHECK-NEXT: vle8.v v11, (a3)
894+
; CHECK-NEXT: vsext.vf2 v12, v8
895+
; CHECK-NEXT: vsext.vf2 v8, v9
896+
; CHECK-NEXT: vsext.vf2 v9, v10
897+
; CHECK-NEXT: vsext.vf2 v10, v11
898+
; CHECK-NEXT: vmul.vv v11, v12, v10
899+
; CHECK-NEXT: vmul.vv v10, v8, v10
900+
; CHECK-NEXT: vdivu.vv v8, v8, v9
901+
; CHECK-NEXT: vor.vv v9, v11, v10
902+
; CHECK-NEXT: vor.vv v8, v9, v8
903+
; CHECK-NEXT: ret
904+
%a = load <2 x i8>, ptr %x
905+
%b = load <2 x i8>, ptr %y
906+
%c = load <2 x i8>, ptr %z
907+
%d = load <2 x i8>, ptr %w
908+
909+
%as = sext <2 x i8> %a to <2 x i16>
910+
%bs = sext <2 x i8> %b to <2 x i16>
911+
%cs = sext <2 x i8> %c to <2 x i16>
912+
%ds = sext <2 x i8> %d to <2 x i16>
913+
914+
%e = mul <2 x i16> %as, %ds
915+
%f = mul <2 x i16> %bs, %ds ; shares 1 use with %e
916+
%g = udiv <2 x i16> %bs, %cs ; shares 1 use with %f, and no uses with %e
917+
918+
%h = or <2 x i16> %e, %f
919+
%i = or <2 x i16> %h, %g
920+
ret <2 x i16> %i
921+
}

0 commit comments

Comments
 (0)