[llvm] 787619a - [AMDGPU] Fix bit-packing condition in LiveRegOptimizer (#201520)
via llvm-commits
llvm-commits at lists.llvm.org
Mon Jun 29 04:47:24 PDT 2026
Author: Steffen Larsen
Date: 2026-06-29T13:47:20+02:00
New Revision: 787619a4072e0eb7887357d5d284e86c17548aed
URL: https://github.com/llvm/llvm-project/commit/787619a4072e0eb7887357d5d284e86c17548aed
DIFF: https://github.com/llvm/llvm-project/commit/787619a4072e0eb7887357d5d284e86c17548aed.diff
LOG: [AMDGPU] Fix bit-packing condition in LiveRegOptimizer (#201520)
This commit changes the condition for determining the eligibility for
bit-packing in LiveRegOptimizer from requiring that the scalar target
type is larger than the source type to instead require that the target
is a multiple of it.
Fixes https://github.com/llvm/llvm-project/issues/196582.
---------
Signed-off-by: Steffen Holst Larsen <sholstla at amd.com>
Added:
llvm/test/CodeGen/AMDGPU/issue196582-late-codegenprepare-crash-non-po2.ll
Modified:
llvm/lib/Target/AMDGPU/AMDGPULateCodeGenPrepare.cpp
Removed:
################################################################################
diff --git a/llvm/lib/Target/AMDGPU/AMDGPULateCodeGenPrepare.cpp b/llvm/lib/Target/AMDGPU/AMDGPULateCodeGenPrepare.cpp
index b5c2b366c8e7b..54bc95653b314 100644
--- a/llvm/lib/Target/AMDGPU/AMDGPULateCodeGenPrepare.cpp
+++ b/llvm/lib/Target/AMDGPU/AMDGPULateCodeGenPrepare.cpp
@@ -115,10 +115,10 @@ class LiveRegOptimizer {
const auto *TLI = ST.getTargetLowering();
Type *EltTy = VTy->getElementType();
- // If the element size is not less than the convert to scalar size, then we
- // can't do any bit packing
+ // If the element size is not is not a multiple scalar size, then we can't
+ // do any bit packing
if (!EltTy->isIntegerTy() ||
- EltTy->getScalarSizeInBits() > ConvertToScalar->getScalarSizeInBits())
+ ConvertToScalar->getScalarSizeInBits() % EltTy->getScalarSizeInBits())
return false;
// Only coerce illegal types
diff --git a/llvm/test/CodeGen/AMDGPU/issue196582-late-codegenprepare-crash-non-po2.ll b/llvm/test/CodeGen/AMDGPU/issue196582-late-codegenprepare-crash-non-po2.ll
new file mode 100644
index 0000000000000..8735e32739d16
--- /dev/null
+++ b/llvm/test/CodeGen/AMDGPU/issue196582-late-codegenprepare-crash-non-po2.ll
@@ -0,0 +1,25 @@
+; NOTE: Assertions have been autogenerated by utils/update_test_checks.py UTC_ARGS: --version 6
+; RUN: opt -S -mtriple=amdgcn-amd-amdhsa -passes=amdgpu-late-codegenprepare %s | FileCheck %s
+
+; Make sure we don't crash on vectors with non-power-of-2 element types.
+; The LiveRegOptimizer's convertToOptType cannot bitcast-pack these into
+; i32 registers because the element size doesn't evenly divide the target size.
+
+define void @non_po2_vector_element(ptr %p, <3 x i1> %mask) {
+; CHECK-LABEL: define void @non_po2_vector_element(
+; CHECK-SAME: ptr [[P:%.*]], <3 x i1> [[MASK:%.*]]) {
+; CHECK-NEXT: [[ENTRY:.*:]]
+; CHECK-NEXT: [[X:%.*]] = call <3 x i31> @llvm.masked.load.v3i31.p0(ptr align 1 [[P]], <3 x i1> [[MASK]], <3 x i31> zeroinitializer)
+; CHECK-NEXT: br label %[[STORE:.*]]
+; CHECK: [[STORE]]:
+; CHECK-NEXT: call void @llvm.masked.store.v3i31.p0(<3 x i31> [[X]], ptr align 1 null, <3 x i1> [[MASK]])
+; CHECK-NEXT: ret void
+;
+entry:
+ %x = call <3 x i31> @llvm.masked.load.v3i31.p0(ptr align 1 %p, <3 x i1> %mask, <3 x i31> zeroinitializer)
+ br label %store
+
+store:
+ call void @llvm.masked.store.v3i31.p0(<3 x i31> %x, ptr align 1 null, <3 x i1> %mask)
+ ret void
+}
More information about the llvm-commits
mailing list