Skip to content

Commit d752f29

Browse files
heihertru
authored andcommitted
[LoongArch] Eliminate the redundant sign extension of division (#107971)
If all incoming values of `div.d` are sign-extended and all users only use the lower 32 bits, then convert them to W versions. Fixes: #107946 (cherry picked from commit 0f47e3a)
1 parent 78654fa commit d752f29

File tree

1 file changed

+15
-0
lines changed

1 file changed

+15
-0
lines changed

llvm/lib/Target/LoongArch/LoongArchOptWInstrs.cpp

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -637,6 +637,19 @@ static bool isSignExtendedW(Register SrcReg, const LoongArchSubtarget &ST,
637637
break;
638638
}
639639
return false;
640+
// If all incoming values are sign-extended and all users only use
641+
// the lower 32 bits, then convert them to W versions.
642+
case LoongArch::DIV_D: {
643+
if (!AddRegToWorkList(MI->getOperand(1).getReg()))
644+
return false;
645+
if (!AddRegToWorkList(MI->getOperand(2).getReg()))
646+
return false;
647+
if (hasAllWUsers(*MI, ST, MRI)) {
648+
FixableDef.insert(MI);
649+
break;
650+
}
651+
return false;
652+
}
640653
}
641654
}
642655

@@ -651,6 +664,8 @@ static unsigned getWOp(unsigned Opcode) {
651664
return LoongArch::ADDI_W;
652665
case LoongArch::ADD_D:
653666
return LoongArch::ADD_W;
667+
case LoongArch::DIV_D:
668+
return LoongArch::DIV_W;
654669
case LoongArch::LD_D:
655670
case LoongArch::LD_WU:
656671
return LoongArch::LD_W;

0 commit comments

Comments
 (0)