Skip to content

Commit 5147468

Browse files
author
Kai Lin
committed
[RISCV][DAGCombiner] Fix missed combines in combineOp_VLToVWOp_VL
The previous implementation of combineOp_VLToVWOp_VL manually replaced old nodes with newly created widened nodes, but only added the new node itself to the DAGCombiner worklist. Since the users of the new node were not added, some combine opportunities could be missed when external DAGCombiner passes expected those users to be reconsidered. This patch replaces the custom replacement logic with a call to DCI.CombineTo(), which performs node replacement in a way consistent with DAGCombiner::Run: - Replace all uses of the old node. - Add the new node and its users to the worklist. - Clean up unused nodes when appropriate. Using CombineTo ensures that combineOp_VLToVWOp_VL behaves consistently with the standard DAGCombiner update model, avoiding discrepancies between the private worklist inside this routine and the global worklist managed by the combiner. This resolves missed combine cases involving VL -> VW operator widening.
1 parent f60ec38 commit 5147468

File tree

2 files changed

+5
-9
lines changed

2 files changed

+5
-9
lines changed

llvm/lib/Target/RISCV/RISCVISelLowering.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18300,8 +18300,7 @@ static SDValue combineOp_VLToVWOp_VL(SDNode *N,
1830018300
}
1830118301
}
1830218302
for (std::pair<SDValue, SDValue> OldNewValues : ValuesToReplace) {
18303-
DAG.ReplaceAllUsesOfValueWith(OldNewValues.first, OldNewValues.second);
18304-
DCI.AddToWorklist(OldNewValues.second.getNode());
18303+
DCI.CombineTo(OldNewValues.first.getNode(), OldNewValues.second);
1830518304
}
1830618305
return InputRootReplacement;
1830718306
}

llvm/test/CodeGen/RISCV/rvv/combine-vl-vw-macc.ll

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,19 +7,16 @@ define void @matmul_min(<32 x i8>* %vptr, i8* %scalars, <32 x i16>* %acc0_ptr, <
77
; CHECK: # %bb.0: # %entry
88
; CHECK-NEXT: li a4, 64
99
; CHECK-NEXT: li a5, 32
10-
; CHECK-NEXT: vsetvli zero, a4, e8, m4, ta, ma
11-
; CHECK-NEXT: vle8.v v8, (a2)
1210
; CHECK-NEXT: vsetvli zero, a5, e8, m2, ta, ma
13-
; CHECK-NEXT: vle8.v v20, (a0)
11+
; CHECK-NEXT: vle8.v v16, (a0)
1412
; CHECK-NEXT: lb a0, 0(a1)
1513
; CHECK-NEXT: lb a1, 1(a1)
1614
; CHECK-NEXT: vsetvli zero, a4, e8, m4, ta, ma
15+
; CHECK-NEXT: vle8.v v8, (a2)
1716
; CHECK-NEXT: vle8.v v12, (a3)
1817
; CHECK-NEXT: vsetvli zero, a5, e8, m2, ta, ma
19-
; CHECK-NEXT: vwmacc.vx v8, a0, v20
20-
; CHECK-NEXT: vwmul.vx v16, v20, a1
21-
; CHECK-NEXT: vsetvli zero, zero, e16, m4, ta, ma
22-
; CHECK-NEXT: vadd.vv v12, v16, v12
18+
; CHECK-NEXT: vwmacc.vx v8, a0, v16
19+
; CHECK-NEXT: vwmacc.vx v12, a1, v16
2320
; CHECK-NEXT: vsetvli zero, a4, e8, m4, ta, ma
2421
; CHECK-NEXT: vse8.v v8, (a2)
2522
; CHECK-NEXT: vse8.v v12, (a3)

0 commit comments

Comments
 (0)