Skip to content

Commit 766f68d

Browse files
committed
[RISCV] Invert if conditions in the switch in RISCVDAGToDAGISel::hasAllNBitUsers. NFC
Make "break" consistently the "if" body and the "return false" the last thing in each case. This makes it easier to add different conditions for different operands of some instructions and makes everything more consistent.
1 parent b7146ae commit 766f68d

File tree

1 file changed

+30
-30
lines changed

1 file changed

+30
-30
lines changed

llvm/lib/Target/RISCV/RISCVISelDAGToDAG.cpp

Lines changed: 30 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -3169,9 +3169,9 @@ bool RISCVDAGToDAGISel::hasAllNBitUsers(SDNode *Node, unsigned Bits,
31693169
case RISCV::FCVT_D_WU:
31703170
case RISCV::TH_REVW:
31713171
case RISCV::TH_SRRIW:
3172-
if (Bits < 32)
3173-
return false;
3174-
break;
3172+
if (Bits >= 32)
3173+
break;
3174+
return false;
31753175
case RISCV::SLL:
31763176
case RISCV::SRA:
31773177
case RISCV::SRL:
@@ -3181,14 +3181,14 @@ bool RISCVDAGToDAGISel::hasAllNBitUsers(SDNode *Node, unsigned Bits,
31813181
case RISCV::BCLR:
31823182
case RISCV::BINV:
31833183
// Shift amount operands only use log2(Xlen) bits.
3184-
if (UI.getOperandNo() != 1 || Bits < Log2_32(Subtarget->getXLen()))
3185-
return false;
3186-
break;
3184+
if (UI.getOperandNo() == 1 && Bits >= Log2_32(Subtarget->getXLen()))
3185+
break;
3186+
return false;
31873187
case RISCV::SLLI:
31883188
// SLLI only uses the lower (XLen - ShAmt) bits.
3189-
if (Bits < Subtarget->getXLen() - User->getConstantOperandVal(1))
3190-
return false;
3191-
break;
3189+
if (Bits >= Subtarget->getXLen() - User->getConstantOperandVal(1))
3190+
break;
3191+
return false;
31923192
case RISCV::ANDI:
31933193
if (Bits >= (unsigned)llvm::bit_width(User->getConstantOperandVal(1)))
31943194
break;
@@ -3224,42 +3224,42 @@ bool RISCVDAGToDAGISel::hasAllNBitUsers(SDNode *Node, unsigned Bits,
32243224
}
32253225
case RISCV::SEXT_B:
32263226
case RISCV::PACKH:
3227-
if (Bits < 8)
3228-
return false;
3229-
break;
3227+
if (Bits >= 8)
3228+
break;
3229+
return false;
32303230
case RISCV::SEXT_H:
32313231
case RISCV::FMV_H_X:
32323232
case RISCV::ZEXT_H_RV32:
32333233
case RISCV::ZEXT_H_RV64:
32343234
case RISCV::PACKW:
3235-
if (Bits < 16)
3236-
return false;
3237-
break;
3235+
if (Bits >= 16)
3236+
break;
3237+
return false;
32383238
case RISCV::PACK:
3239-
if (Bits < (Subtarget->getXLen() / 2))
3240-
return false;
3241-
break;
3239+
if (Bits >= (Subtarget->getXLen() / 2))
3240+
break;
3241+
return false;
32423242
case RISCV::ADD_UW:
32433243
case RISCV::SH1ADD_UW:
32443244
case RISCV::SH2ADD_UW:
32453245
case RISCV::SH3ADD_UW:
32463246
// The first operand to add.uw/shXadd.uw is implicitly zero extended from
32473247
// 32 bits.
3248-
if (UI.getOperandNo() != 0 || Bits < 32)
3249-
return false;
3250-
break;
3248+
if (UI.getOperandNo() == 0 && Bits >= 32)
3249+
break;
3250+
return false;
32513251
case RISCV::SB:
3252-
if (UI.getOperandNo() != 0 || Bits < 8)
3253-
return false;
3254-
break;
3252+
if (UI.getOperandNo() == 0 && Bits >= 8)
3253+
break;
3254+
return false;
32553255
case RISCV::SH:
3256-
if (UI.getOperandNo() != 0 || Bits < 16)
3257-
return false;
3258-
break;
3256+
if (UI.getOperandNo() == 0 && Bits >= 16)
3257+
break;
3258+
return false;
32593259
case RISCV::SW:
3260-
if (UI.getOperandNo() != 0 || Bits < 32)
3261-
return false;
3262-
break;
3260+
if (UI.getOperandNo() == 0 && Bits >= 32)
3261+
break;
3262+
return false;
32633263
}
32643264
}
32653265

0 commit comments

Comments
 (0)