Skip to content

Commit

Permalink
[LoongArch] Eliminate the redundant sign extension of division (#107971)
Browse files Browse the repository at this point in the history
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)
  • Loading branch information
heiher authored and tru committed Sep 16, 2024
1 parent 78654fa commit d752f29
Showing 1 changed file with 15 additions and 0 deletions.
15 changes: 15 additions & 0 deletions llvm/lib/Target/LoongArch/LoongArchOptWInstrs.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -637,6 +637,19 @@ static bool isSignExtendedW(Register SrcReg, const LoongArchSubtarget &ST,
break;
}
return false;
// If all incoming values are sign-extended and all users only use
// the lower 32 bits, then convert them to W versions.
case LoongArch::DIV_D: {
if (!AddRegToWorkList(MI->getOperand(1).getReg()))
return false;
if (!AddRegToWorkList(MI->getOperand(2).getReg()))
return false;
if (hasAllWUsers(*MI, ST, MRI)) {
FixableDef.insert(MI);
break;
}
return false;
}
}
}

Expand All @@ -651,6 +664,8 @@ static unsigned getWOp(unsigned Opcode) {
return LoongArch::ADDI_W;
case LoongArch::ADD_D:
return LoongArch::ADD_W;
case LoongArch::DIV_D:
return LoongArch::DIV_W;
case LoongArch::LD_D:
case LoongArch::LD_WU:
return LoongArch::LD_W;
Expand Down

0 comments on commit d752f29

Please sign in to comment.