[llvm] 0053867 - [SPIR-V] Fix truncation of nonzero constant bool argument in group builtins (#214142)

via llvm-commits llvm-commits at lists.llvm.org
Wed Aug 5 04:00:26 PDT 2026


Author: Arseniy Obolenskiy
Date: 2026-08-05T13:00:21+02:00
New Revision: 00538679490158b50e1102b6a6e4e1b14810ba29

URL: https://github.com/llvm/llvm-project/commit/00538679490158b50e1102b6a6e4e1b14810ba29
DIFF: https://github.com/llvm/llvm-project/commit/00538679490158b50e1102b6a6e4e1b14810ba29.diff

LOG: [SPIR-V] Fix truncation of nonzero constant bool argument in group builtins (#214142)

buildConstantInt truncated the raw constant to its low bit instead of
testing it against zero, silently miscompiling calls like
work_group_all(4) to false

Added: 
    

Modified: 
    llvm/lib/Target/SPIRV/SPIRVBuiltins.cpp
    llvm/test/CodeGen/SPIRV/transcoding/OpGroupAllAny.ll

Removed: 
    


################################################################################
diff  --git a/llvm/lib/Target/SPIRV/SPIRVBuiltins.cpp b/llvm/lib/Target/SPIRV/SPIRVBuiltins.cpp
index c482807c02ec6..a18a5feb4fa8a 100644
--- a/llvm/lib/Target/SPIRV/SPIRVBuiltins.cpp
+++ b/llvm/lib/Target/SPIRV/SPIRVBuiltins.cpp
@@ -1383,7 +1383,7 @@ static bool generateGroupInst(const SPIRV::IncomingCall *Call,
     MachineInstr *ArgInstruction = getDefInstrMaybeConstant(BoolReg, MRI);
     if (ArgInstruction->getOpcode() == TargetOpcode::G_CONSTANT) {
       if (BoolRegType->getOpcode() != SPIRV::OpTypeBool)
-        Arg0 = GR->buildConstantInt(getIConstVal(BoolReg, MRI), MIRBuilder,
+        Arg0 = GR->buildConstantInt(getIConstVal(BoolReg, MRI) != 0, MIRBuilder,
                                     BoolType, true);
     } else {
       if (BoolRegType->getOpcode() == SPIRV::OpTypeInt) {

diff  --git a/llvm/test/CodeGen/SPIRV/transcoding/OpGroupAllAny.ll b/llvm/test/CodeGen/SPIRV/transcoding/OpGroupAllAny.ll
index 2a503a189906d..8ab2ecb9f1ad7 100644
--- a/llvm/test/CodeGen/SPIRV/transcoding/OpGroupAllAny.ll
+++ b/llvm/test/CodeGen/SPIRV/transcoding/OpGroupAllAny.ll
@@ -14,12 +14,16 @@
 ; CHECK-SPIRV: %[[#]] = OpGroupAny %[[#BoolTypeID]] %[[#]] %[[#True]]
 ; CHECK-SPIRV: %[[#]] = OpGroupAll %[[#BoolTypeID]] %[[#]] %[[#True]]
 ; CHECK-SPIRV: %[[#]] = OpGroupAny %[[#BoolTypeID]] %[[#]] %[[#False]]
+; CHECK-SPIRV: %[[#]] = OpGroupAll %[[#BoolTypeID]] %[[#]] %[[#True]]
+; CHECK-SPIRV: %[[#]] = OpGroupAny %[[#BoolTypeID]] %[[#]] %[[#True]]
 define spir_kernel void @test(ptr addrspace(1) nocapture readnone %i) {
 entry:
   %call = tail call spir_func i32 @_Z14work_group_alli(i32 5)
   %call1 = tail call spir_func i32 @_Z14work_group_anyi(i32 5)
   %call3 = tail call spir_func i32 @__spirv_GroupAll(i32 0, i1 1)
   %call4 = tail call spir_func i32 @__spirv_GroupAny(i32 0, i1 0)
+  %call5 = tail call spir_func i32 @_Z14work_group_alli(i32 4)
+  %call6 = tail call spir_func i32 @_Z14work_group_anyi(i32 4)
   ret void
 }
 


        


More information about the llvm-commits mailing list