Skip to content

Commit cfc574a

Browse files
committed
[RISCV] Use the OperandTransform field of a couple PatLeafs to simplify isel patterns. NFC
1 parent 204234a commit cfc574a

File tree

1 file changed

+14
-14
lines changed

1 file changed

+14
-14
lines changed

llvm/lib/Target/RISCV/RISCVInstrInfoZb.td

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -149,13 +149,23 @@ def BCLRIANDIMaskLow : SDNodeXForm<imm, [{
149149
SDLoc(N), N->getValueType(0));
150150
}]>;
151151

152+
def SimmShiftRightBy2XForm : SDNodeXForm<imm, [{
153+
return CurDAG->getSignedTargetConstant(N->getSExtValue() >> 2, SDLoc(N),
154+
N->getValueType(0));
155+
}]>;
156+
157+
def SimmShiftRightBy3XForm : SDNodeXForm<imm, [{
158+
return CurDAG->getSignedTargetConstant(N->getSExtValue() >> 3, SDLoc(N),
159+
N->getValueType(0));
160+
}]>;
161+
152162
def CSImm12MulBy4 : PatLeaf<(imm), [{
153163
if (!N->hasOneUse())
154164
return false;
155165
int64_t C = N->getSExtValue();
156166
// Skip if C is simm12, an lui, or can be optimized by the PatLeaf AddiPair.
157167
return !isInt<13>(C) && !isShiftedInt<20, 12>(C) && isShiftedInt<12, 2>(C);
158-
}]>;
168+
}], SimmShiftRightBy2XForm>;
159169

160170
def CSImm12MulBy8 : PatLeaf<(imm), [{
161171
if (!N->hasOneUse())
@@ -164,17 +174,7 @@ def CSImm12MulBy8 : PatLeaf<(imm), [{
164174
// Skip if C is simm12, an lui or can be optimized by the PatLeaf AddiPair or
165175
// CSImm12MulBy4.
166176
return !isInt<14>(C) && !isShiftedInt<20, 12>(C) && isShiftedInt<12, 3>(C);
167-
}]>;
168-
169-
def SimmShiftRightBy2XForm : SDNodeXForm<imm, [{
170-
return CurDAG->getSignedTargetConstant(N->getSExtValue() >> 2, SDLoc(N),
171-
N->getValueType(0));
172-
}]>;
173-
174-
def SimmShiftRightBy3XForm : SDNodeXForm<imm, [{
175-
return CurDAG->getSignedTargetConstant(N->getSExtValue() >> 3, SDLoc(N),
176-
N->getValueType(0));
177-
}]>;
177+
}], SimmShiftRightBy3XForm>;
178178

179179
// Pattern to exclude simm12 immediates from matching, namely `non_imm12`.
180180
// GISel currently doesn't support PatFrag for leaf nodes, so `non_imm12`
@@ -654,10 +654,10 @@ foreach i = {1,2,3} in {
654654
}
655655

656656
def : Pat<(add_like (XLenVT GPR:$r), CSImm12MulBy4:$i),
657-
(SH2ADD (XLenVT (ADDI (XLenVT X0), (SimmShiftRightBy2XForm CSImm12MulBy4:$i))),
657+
(SH2ADD (XLenVT (ADDI (XLenVT X0), CSImm12MulBy4:$i)),
658658
GPR:$r)>;
659659
def : Pat<(add_like (XLenVT GPR:$r), CSImm12MulBy8:$i),
660-
(SH3ADD (XLenVT (ADDI (XLenVT X0), (SimmShiftRightBy3XForm CSImm12MulBy8:$i))),
660+
(SH3ADD (XLenVT (ADDI (XLenVT X0), CSImm12MulBy8:$i)),
661661
GPR:$r)>;
662662

663663
} // Predicates = [HasStdExtZba]

0 commit comments

Comments
 (0)