Skip to content

Commit 3265a36

Browse files
authored
[RISCV] Refactor RISCVDAGToDAGISel::selectSimm5Shl2. NFC (#148731)
Return from the for loop body instead of using a break and checking the shift amount after.
1 parent eea5c29 commit 3265a36

File tree

1 file changed

+11
-14
lines changed

1 file changed

+11
-14
lines changed

llvm/lib/Target/RISCV/RISCVISelDAGToDAG.cpp

Lines changed: 11 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -3776,21 +3776,18 @@ bool RISCVDAGToDAGISel::hasAllNBitUsers(SDNode *Node, unsigned Bits,
37763776
// Select a constant that can be represented as (sign_extend(imm5) << imm2).
37773777
bool RISCVDAGToDAGISel::selectSimm5Shl2(SDValue N, SDValue &Simm5,
37783778
SDValue &Shl2) {
3779-
if (auto *C = dyn_cast<ConstantSDNode>(N)) {
3780-
int64_t Offset = C->getSExtValue();
3781-
unsigned Shift;
3782-
for (Shift = 0; Shift < 4; Shift++)
3783-
if (isInt<5>(Offset >> Shift) && ((Offset % (1LL << Shift)) == 0))
3784-
break;
3785-
3786-
// Constant cannot be encoded.
3787-
if (Shift == 4)
3788-
return false;
3779+
auto *C = dyn_cast<ConstantSDNode>(N);
3780+
if (!C)
3781+
return false;
37893782

3790-
EVT Ty = N->getValueType(0);
3791-
Simm5 = CurDAG->getSignedTargetConstant(Offset >> Shift, SDLoc(N), Ty);
3792-
Shl2 = CurDAG->getTargetConstant(Shift, SDLoc(N), Ty);
3793-
return true;
3783+
int64_t Offset = C->getSExtValue();
3784+
for (unsigned Shift = 0; Shift < 4; Shift++) {
3785+
if (isInt<5>(Offset >> Shift) && ((Offset % (1LL << Shift)) == 0)) {
3786+
EVT VT = N->getValueType(0);
3787+
Simm5 = CurDAG->getSignedTargetConstant(Offset >> Shift, SDLoc(N), VT);
3788+
Shl2 = CurDAG->getTargetConstant(Shift, SDLoc(N), VT);
3789+
return true;
3790+
}
37943791
}
37953792

37963793
return false;

0 commit comments

Comments
 (0)