Skip to content

Conversation

@topperc
Copy link
Collaborator

@topperc topperc commented Nov 18, 2025

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.

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.
@llvmbot
Copy link
Member

llvmbot commented Nov 18, 2025

@llvm/pr-subscribers-llvm-globalisel

Author: Craig Topper (topperc)

Changes

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.


Full diff: https://github.com/llvm/llvm-project/pull/168584.diff

1 Files Affected:

  • (modified) llvm/lib/CodeGen/GlobalISel/LegalizerHelper.cpp (+3-3)
diff --git a/llvm/lib/CodeGen/GlobalISel/LegalizerHelper.cpp b/llvm/lib/CodeGen/GlobalISel/LegalizerHelper.cpp
index ba28e4dda3313..8a9a297805583 100644
--- a/llvm/lib/CodeGen/GlobalISel/LegalizerHelper.cpp
+++ b/llvm/lib/CodeGen/GlobalISel/LegalizerHelper.cpp
@@ -7609,7 +7609,7 @@ LegalizerHelper::lowerBitCount(MachineInstr &MI) {
   }
   case TargetOpcode::G_CTLZ: {
     auto [DstReg, DstTy, SrcReg, SrcTy] = MI.getFirst2RegLLTs();
-    unsigned Len = SrcTy.getSizeInBits();
+    unsigned Len = SrcTy.getScalarSizeInBits();
 
     if (isSupported({TargetOpcode::G_CTLZ_ZERO_UNDEF, {DstTy, SrcTy}})) {
       // If CTLZ_ZERO_UNDEF is supported, emit that and a select for zero.
@@ -7657,7 +7657,7 @@ LegalizerHelper::lowerBitCount(MachineInstr &MI) {
   case TargetOpcode::G_CTTZ: {
     auto [DstReg, DstTy, SrcReg, SrcTy] = MI.getFirst2RegLLTs();
 
-    unsigned Len = SrcTy.getSizeInBits();
+    unsigned Len = SrcTy.getScalarSizeInBits();
     if (isSupported({TargetOpcode::G_CTTZ_ZERO_UNDEF, {DstTy, SrcTy}})) {
       // If CTTZ_ZERO_UNDEF is legal or custom, emit that and a select with
       // zero.
@@ -7695,7 +7695,7 @@ LegalizerHelper::lowerBitCount(MachineInstr &MI) {
   case TargetOpcode::G_CTPOP: {
     Register SrcReg = MI.getOperand(1).getReg();
     LLT Ty = MRI.getType(SrcReg);
-    unsigned Size = Ty.getSizeInBits();
+    unsigned Size = Ty.getScalarSizeInBits();
     MachineIRBuilder &B = MIRBuilder;
 
     // Count set bits in blocks of 2 bits. Default approach would be

Copy link
Collaborator

@preames preames left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@github-actions
Copy link

🐧 Linux x64 Test Results

  • 186332 tests passed
  • 4859 tests skipped

@topperc topperc merged commit 1157a22 into llvm:main Nov 18, 2025
10 of 11 checks passed
@llvm-ci
Copy link
Collaborator

llvm-ci commented Nov 18, 2025

LLVM Buildbot has detected a new failure on builder clang-m68k-linux-cross running on suse-gary-m68k-cross while building llvm at step 1 "checkout".

Full details are available at: https://lab.llvm.org/buildbot/#/builders/27/builds/19113

Here is the relevant piece of the build log for the reference
Step 1 (checkout) failure: update (failure)
git version 2.46.1
error: RPC failed; HTTP 500 curl 22 The requested URL returned error: 500
fatal: expected flush after ref listing
remote: Internal Server Error
fatal: unable to access 'https://github.com/llvm/llvm-project.git/': The requested URL returned error: 500

@llvm-ci
Copy link
Collaborator

llvm-ci commented Nov 18, 2025

LLVM Buildbot has detected a new failure on builder sanitizer-aarch64-linux-fuzzer running on sanitizer-buildbot12 while building llvm at step 1 "update-annotate-scripts".

Full details are available at: https://lab.llvm.org/buildbot/#/builders/159/builds/35435

Here is the relevant piece of the build log for the reference
Step 1 (update-annotate-scripts) failure: update (failure)
git version 2.48.1
remote: Internal Server Error
fatal: unable to access 'https://github.com/llvm/llvm-zorg.git/': The requested URL returned error: 500
remote: Internal Server Error
fatal: unable to access 'https://github.com/llvm/llvm-zorg.git/': The requested URL returned error: 500

@llvm-ci
Copy link
Collaborator

llvm-ci commented Nov 18, 2025

LLVM Buildbot has detected a new failure on builder clangd-ubuntu-tsan running on clangd-ubuntu-clang while building llvm at step 2 "checkout".

Full details are available at: https://lab.llvm.org/buildbot/#/builders/134/builds/30041

Here is the relevant piece of the build log for the reference
Step 2 (checkout) failure: update (failure)
git version 2.17.1
remote: Internal Server Error
fatal: unable to access 'https://github.com/llvm/llvm-project.git/': The requested URL returned error: 500
remote: Internal Server Error
fatal: unable to access 'https://github.com/llvm/llvm-project.git/': The requested URL returned error: 500

@llvm-ci
Copy link
Collaborator

llvm-ci commented Nov 18, 2025

LLVM Buildbot has detected a new failure on builder libc-x86_64-debian-dbg-bootstrap-build running on libc-x86_64-debian while building llvm at step 2 "update-annotated-scripts".

Full details are available at: https://lab.llvm.org/buildbot/#/builders/200/builds/20535

Here is the relevant piece of the build log for the reference
Step 2 (update-annotated-scripts) failure: update (failure)
git version 2.39.5
remote: Internal Server Error
fatal: unable to access 'https://github.com/llvm/llvm-zorg.git/': The requested URL returned error: 500
remote: Internal Server Error
fatal: unable to access 'https://github.com/llvm/llvm-zorg.git/': The requested URL returned error: 500

@llvm-ci
Copy link
Collaborator

llvm-ci commented Nov 18, 2025

LLVM Buildbot has detected a new failure on builder libc-x86_64-debian-fullbuild-dbg-asan running on libc-x86_64-debian-fullbuild while building llvm at step 2 "update-annotated-scripts".

Full details are available at: https://lab.llvm.org/buildbot/#/builders/171/builds/34808

Here is the relevant piece of the build log for the reference
Step 2 (update-annotated-scripts) failure: update (failure)
git version 2.39.5
remote: Internal Server Error
fatal: unable to access 'https://github.com/llvm/llvm-zorg.git/': The requested URL returned error: 500
remote: Internal Server Error
fatal: unable to access 'https://github.com/llvm/llvm-zorg.git/': The requested URL returned error: 500

@llvm-ci
Copy link
Collaborator

llvm-ci commented Nov 18, 2025

LLVM Buildbot has detected a new failure on builder lldb-aarch64-ubuntu running on linaro-lldb-aarch64-ubuntu while building llvm at step 1 "checkout".

Full details are available at: https://lab.llvm.org/buildbot/#/builders/59/builds/27520

Here is the relevant piece of the build log for the reference
Step 1 (checkout) failure: update (failure)
git version 2.34.1
remote: Internal Server Error
fatal: unable to access 'https://github.com/llvm/llvm-project.git/': The requested URL returned error: 500
remote: Internal Server Error
fatal: unable to access 'https://github.com/llvm/llvm-project.git/': The requested URL returned error: 500

@llvm-ci
Copy link
Collaborator

llvm-ci commented Nov 18, 2025

LLVM Buildbot has detected a new failure on builder libc-x86_64-debian-dbg running on libc-x86_64-debian while building llvm at step 2 "update-annotated-scripts".

Full details are available at: https://lab.llvm.org/buildbot/#/builders/93/builds/34085

Here is the relevant piece of the build log for the reference
Step 2 (update-annotated-scripts) failure: update (failure)
git version 2.39.5
remote: Internal Server Error
fatal: unable to access 'https://github.com/llvm/llvm-zorg.git/': The requested URL returned error: 500
remote: Internal Server Error
fatal: unable to access 'https://github.com/llvm/llvm-zorg.git/': The requested URL returned error: 500

@llvm-ci
Copy link
Collaborator

llvm-ci commented Nov 18, 2025

LLVM Buildbot has detected a new failure on builder clang-hip-vega20 running on hip-vega20-0 while building llvm at step 2 "update-annotated-scripts".

Full details are available at: https://lab.llvm.org/buildbot/#/builders/123/builds/30892

Here is the relevant piece of the build log for the reference
Step 2 (update-annotated-scripts) failure: update (failure)
git version 2.34.1
remote: Internal Server Error
fatal: unable to access 'https://github.com/llvm/llvm-zorg.git/': The requested URL returned error: 500
remote: Internal Server Error
fatal: unable to access 'https://github.com/llvm/llvm-zorg.git/': The requested URL returned error: 500

@llvm-ci
Copy link
Collaborator

llvm-ci commented Nov 18, 2025

LLVM Buildbot has detected a new failure on builder clang-x86_64-linux-abi-test running on sie-linux-worker2 while building llvm at step 2 "Checkout test-suite".

Full details are available at: https://lab.llvm.org/buildbot/#/builders/8/builds/23703

Here is the relevant piece of the build log for the reference
Step 2 (Checkout test-suite) failure: update (failure)
git version 2.34.1
fatal: unable to access 'https://github.com/llvm/llvm-test-suite.git/': The requested URL returned error: 503
remote: Internal Server Error
fatal: unable to access 'https://github.com/llvm/llvm-test-suite.git/': The requested URL returned error: 500

@llvm-ci
Copy link
Collaborator

llvm-ci commented Nov 18, 2025

LLVM Buildbot has detected a new failure on builder openmp-offload-amdgpu-runtime-2 running on rocm-worker-hw-02 while building llvm at step 2 "checkout".

Full details are available at: https://lab.llvm.org/buildbot/#/builders/10/builds/17581

Here is the relevant piece of the build log for the reference
Step 2 (checkout) failure: update (failure)
git version 2.34.1
fatal: unable to access 'https://github.com/llvm/llvm-project.git/': The requested URL returned error: 502
remote: Internal Server Error
fatal: unable to access 'https://github.com/llvm/llvm-project.git/': The requested URL returned error: 500

@llvm-ci
Copy link
Collaborator

llvm-ci commented Nov 18, 2025

LLVM Buildbot has detected a new failure on builder mlir-nvidia-gcc7 running on mlir-nvidia while building llvm at step 2 "checkout".

Full details are available at: https://lab.llvm.org/buildbot/#/builders/116/builds/21152

Here is the relevant piece of the build log for the reference
Step 2 (checkout) failure: update (failure)
git version 2.34.1
remote: Internal Server Error
fatal: unable to access 'https://github.com/llvm/llvm-project.git/': The requested URL returned error: 500
remote: Internal Server Error
fatal: unable to access 'https://github.com/llvm/llvm-project.git/': The requested URL returned error: 500

@llvm-ci
Copy link
Collaborator

llvm-ci commented Nov 18, 2025

LLVM Buildbot has detected a new failure on builder lldb-remote-linux-ubuntu running on as-builder-9 while building llvm at step 4 "checkout".

Full details are available at: https://lab.llvm.org/buildbot/#/builders/195/builds/17548

Here is the relevant piece of the build log for the reference
Step 4 (checkout) failure: update (failure)
git version 2.43.0
remote: Internal Server Error
fatal: unable to access 'https://github.com/llvm/llvm-project.git/': The requested URL returned error: 500
remote: Internal Server Error
fatal: unable to access 'https://github.com/llvm/llvm-project.git/': The requested URL returned error: 500

@llvm-ci
Copy link
Collaborator

llvm-ci commented Nov 18, 2025

LLVM Buildbot has detected a new failure on builder llvm-clang-x86_64-gcc-ubuntu running on sie-linux-worker3 while building llvm at step 2 "checkout".

Full details are available at: https://lab.llvm.org/buildbot/#/builders/174/builds/27671

Here is the relevant piece of the build log for the reference
Step 2 (checkout) failure: update (failure)
git version 2.25.1
remote: Internal Server Error
fatal: unable to access 'https://github.com/llvm/llvm-project.git/': The requested URL returned error: 500
remote: Internal Server Error
fatal: unable to access 'https://github.com/llvm/llvm-project.git/': The requested URL returned error: 500

@llvm-ci
Copy link
Collaborator

llvm-ci commented Nov 18, 2025

LLVM Buildbot has detected a new failure on builder flang-aarch64-dylib running on linaro-flang-aarch64-dylib while building llvm at step 2 "checkout".

Full details are available at: https://lab.llvm.org/buildbot/#/builders/50/builds/17831

Here is the relevant piece of the build log for the reference
Step 2 (checkout) failure: update (failure)
git version 2.34.1
remote: Internal Server Error
fatal: unable to access 'https://github.com/llvm/llvm-project.git/': The requested URL returned error: 500
remote: Internal Server Error
fatal: unable to access 'https://github.com/llvm/llvm-project.git/': The requested URL returned error: 500

@llvm-ci
Copy link
Collaborator

llvm-ci commented Nov 18, 2025

LLVM Buildbot has detected a new failure on builder clang-riscv-gauntlet running on rise-worker-1 while building llvm at step 3 "update-annotated-scripts".

Full details are available at: https://lab.llvm.org/buildbot/#/builders/210/builds/5500

Here is the relevant piece of the build log for the reference
Step 3 (update-annotated-scripts) failure: update (failure)
git version 2.50.0
remote: Internal Server Error
fatal: unable to access 'https://github.com/llvm/llvm-zorg.git/': The requested URL returned error: 500
remote: Internal Server Error
fatal: unable to access 'https://github.com/llvm/llvm-zorg.git/': The requested URL returned error: 500

@llvm-ci
Copy link
Collaborator

llvm-ci commented Nov 18, 2025

LLVM Buildbot has detected a new failure on builder llvm-nvptx-nvidia-win running on as-builder-8 while building llvm at step 2 "checkout".

Full details are available at: https://lab.llvm.org/buildbot/#/builders/54/builds/14816

Here is the relevant piece of the build log for the reference
Step 2 (checkout) failure: update (failure)
git version 2.41.0.windows.3
remote: Internal Server Error
fatal: unable to access 'https://github.com/llvm/llvm-project.git/': The requested URL returned error: 500
remote: Internal Server Error
fatal: unable to access 'https://github.com/llvm/llvm-project.git/': The requested URL returned error: 500

@llvm-ci
Copy link
Collaborator

llvm-ci commented Nov 18, 2025

LLVM Buildbot has detected a new failure on builder flang-aarch64-release running on linaro-flang-aarch64-release while building llvm at step 2 "checkout".

Full details are available at: https://lab.llvm.org/buildbot/#/builders/172/builds/17053

Here is the relevant piece of the build log for the reference
Step 2 (checkout) failure: update (failure)
git version 2.34.1
remote: Internal Server Error
fatal: unable to access 'https://github.com/llvm/llvm-project.git/': The requested URL returned error: 500
remote: Internal Server Error
fatal: unable to access 'https://github.com/llvm/llvm-project.git/': The requested URL returned error: 500

@llvm-ci
Copy link
Collaborator

llvm-ci commented Nov 18, 2025

LLVM Buildbot has detected a new failure on builder llvm-nvptx64-nvidia-win running on as-builder-8 while building llvm at step 2 "checkout".

Full details are available at: https://lab.llvm.org/buildbot/#/builders/155/builds/14961

Here is the relevant piece of the build log for the reference
Step 2 (checkout) failure: update (failure)
git version 2.41.0.windows.3
remote: Internal Server Error
fatal: unable to access 'https://github.com/llvm/llvm-project.git/': The requested URL returned error: 500
remote: Internal Server Error
fatal: unable to access 'https://github.com/llvm/llvm-project.git/': The requested URL returned error: 500

@llvm-ci
Copy link
Collaborator

llvm-ci commented Nov 18, 2025

LLVM Buildbot has detected a new failure on builder sanitizer-x86_64-linux-bootstrap-msan running on sanitizer-buildbot5 while building llvm at step 1 "update-annotate-scripts".

Full details are available at: https://lab.llvm.org/buildbot/#/builders/164/builds/15782

Here is the relevant piece of the build log for the reference
Step 1 (update-annotate-scripts) failure: update (failure)
git version 2.48.1
remote: Internal Server Error
fatal: unable to access 'https://github.com/llvm/llvm-zorg.git/': The requested URL returned error: 500
remote: Internal Server Error
fatal: unable to access 'https://github.com/llvm/llvm-zorg.git/': The requested URL returned error: 500

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants