Skip to content

Commit 1157a22

Browse files
authored
[GISel] Use getScalarSizeInBits in LegalizerHelper::lowerBitCount (#168584)
For vectors, CTLZ, CTTZ, CTPOP all operate on individual elements. The lowering should be based on the element width. I noticed this by inspection. No tests in tree are currently affected, but I thought it would be good to fix so someone doesn't have to debug it in the future.
1 parent 56b1d42 commit 1157a22

File tree

1 file changed

+3
-3
lines changed

1 file changed

+3
-3
lines changed

llvm/lib/CodeGen/GlobalISel/LegalizerHelper.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7609,7 +7609,7 @@ LegalizerHelper::lowerBitCount(MachineInstr &MI) {
76097609
}
76107610
case TargetOpcode::G_CTLZ: {
76117611
auto [DstReg, DstTy, SrcReg, SrcTy] = MI.getFirst2RegLLTs();
7612-
unsigned Len = SrcTy.getSizeInBits();
7612+
unsigned Len = SrcTy.getScalarSizeInBits();
76137613

76147614
if (isSupported({TargetOpcode::G_CTLZ_ZERO_UNDEF, {DstTy, SrcTy}})) {
76157615
// If CTLZ_ZERO_UNDEF is supported, emit that and a select for zero.
@@ -7657,7 +7657,7 @@ LegalizerHelper::lowerBitCount(MachineInstr &MI) {
76577657
case TargetOpcode::G_CTTZ: {
76587658
auto [DstReg, DstTy, SrcReg, SrcTy] = MI.getFirst2RegLLTs();
76597659

7660-
unsigned Len = SrcTy.getSizeInBits();
7660+
unsigned Len = SrcTy.getScalarSizeInBits();
76617661
if (isSupported({TargetOpcode::G_CTTZ_ZERO_UNDEF, {DstTy, SrcTy}})) {
76627662
// If CTTZ_ZERO_UNDEF is legal or custom, emit that and a select with
76637663
// zero.
@@ -7695,7 +7695,7 @@ LegalizerHelper::lowerBitCount(MachineInstr &MI) {
76957695
case TargetOpcode::G_CTPOP: {
76967696
Register SrcReg = MI.getOperand(1).getReg();
76977697
LLT Ty = MRI.getType(SrcReg);
7698-
unsigned Size = Ty.getSizeInBits();
7698+
unsigned Size = Ty.getScalarSizeInBits();
76997699
MachineIRBuilder &B = MIRBuilder;
77007700

77017701
// Bail out on irregular type lengths.

0 commit comments

Comments
 (0)