From 45ae7d166ddf7265eddcfe9d0969a3408a2c7384 Mon Sep 17 00:00:00 2001 From: Justin Bogner Date: Mon, 4 Nov 2024 05:23:43 -0800 Subject: [PATCH] [SPIRV] Fix assert in `getOrCreateBaseRegister` for `i32 -1` (#114630) When trying to create a const inst from a 32 bit signed value, we don't want to sign-extend it to 64 bits, as the resulting value won't actually fit in an `i32` if it was negative. This fixes crashes in the following two tests after the APInt constructor asserts were enabled in #114539: ``` Failed Tests (2): LLVM :: CodeGen/SPIRV/transcoding/RelationalOperators.ll LLVM :: CodeGen/SPIRV/uitofp-with-bool.ll ``` --- llvm/lib/Target/SPIRV/SPIRVGlobalRegistry.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/llvm/lib/Target/SPIRV/SPIRVGlobalRegistry.cpp b/llvm/lib/Target/SPIRV/SPIRVGlobalRegistry.cpp index 62bd8d1f9d2433..af0df4d6e5d563 100644 --- a/llvm/lib/Target/SPIRV/SPIRVGlobalRegistry.cpp +++ b/llvm/lib/Target/SPIRV/SPIRVGlobalRegistry.cpp @@ -400,7 +400,7 @@ Register SPIRVGlobalRegistry::getOrCreateBaseRegister( } assert(Type->getOpcode() == SPIRV::OpTypeInt); SPIRVType *SpvBaseType = getOrCreateSPIRVIntegerType(BitWidth, I, TII); - return getOrCreateConstInt(Val->getUniqueInteger().getSExtValue(), I, + return getOrCreateConstInt(Val->getUniqueInteger().getZExtValue(), I, SpvBaseType, TII, ZeroAsNull); }