Skip to content

Commit 9408b96

Browse files
Use getIConstantVRegSExtVal
1 parent 0e1d1d7 commit 9408b96

File tree

1 file changed

+3
-4
lines changed

1 file changed

+3
-4
lines changed

llvm/lib/Target/RISCV/GISel/RISCVInstructionSelector.cpp

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -537,12 +537,11 @@ void RISCVInstructionSelector::getICMPOperandsForBranch(
537537
RHS = MI.getOperand(3).getReg();
538538

539539
// Adjust comparisons to use comparison with 0 if possible.
540-
int64_t Constant;
541-
if (mi_match(RHS, MRI, m_ICst(Constant))) {
540+
if (auto Constant = getIConstantVRegSExtVal(RHS, MRI)) {
542541
switch (ICMPCC) {
543542
case CmpInst::Predicate::ICMP_SGT:
544543
// Convert X > -1 to X >= 0
545-
if (Constant == -1) {
544+
if (*Constant == -1) {
546545
MachineInstr *Zero = MIB.buildConstant(MRI.getType(RHS), 0);
547546
selectConstant(*Zero, MIB, MRI);
548547
CC = RISCVCC::COND_GE;
@@ -552,7 +551,7 @@ void RISCVInstructionSelector::getICMPOperandsForBranch(
552551
break;
553552
case CmpInst::Predicate::ICMP_SLT:
554553
// Convert X < 1 to 0 >= X
555-
if (Constant == 1) {
554+
if (*Constant == 1) {
556555
MachineInstr *Zero = MIB.buildConstant(MRI.getType(RHS), 0);
557556
selectConstant(*Zero, MIB, MRI);
558557
CC = RISCVCC::COND_GE;

0 commit comments

Comments
 (0)