From ca1bc71e17f013130f1a2951805cc7b482dcf34b Mon Sep 17 00:00:00 2001 From: Mirko Brkusanin Date: Mon, 6 Nov 2023 17:51:03 +0100 Subject: [PATCH] Update llpc to handle new version of llvm Handle upstream llvm changes for https://github.com/llvm/llvm-project/commit/e4a4122eb6768b69640173b4c32fd88de4547227 [IR] Remove zext and sext constant expressions (#71040) --- llpc/translator/lib/SPIRV/SPIRVReader.cpp | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/llpc/translator/lib/SPIRV/SPIRVReader.cpp b/llpc/translator/lib/SPIRV/SPIRVReader.cpp index 410b8083ba..6d677c897a 100644 --- a/llpc/translator/lib/SPIRV/SPIRVReader.cpp +++ b/llpc/translator/lib/SPIRV/SPIRVReader.cpp @@ -55,6 +55,7 @@ #include "lgc/Pipeline.h" #include "llvm/ADT/DenseMap.h" #include "llvm/ADT/StringSwitch.h" +#include "llvm/Analysis/ConstantFolding.h" #include "llvm/Analysis/VectorUtils.h" #include "llvm/BinaryFormat/Dwarf.h" #include "llvm/IR/CFG.h" @@ -2011,8 +2012,12 @@ Constant *SPIRVToLLVM::buildConstStoreRecursively(SPIRVType *const spvType, Type return ConstantArray::get(cast(storeType), constElements); } // If the store was a bool or vector of bool, need to zext the storing value. - if (spvType->isTypeBool() || (spvType->isTypeVector() && spvType->getVectorComponentType()->isTypeBool())) - constStoreValue = ConstantExpr::getZExtOrBitCast(constStoreValue, storeType); + if (spvType->isTypeBool() || (spvType->isTypeVector() && spvType->getVectorComponentType()->isTypeBool())) { + if (constStoreValue->getType() != storeType) { + constStoreValue = ConstantFoldCastOperand(Instruction::ZExt, constStoreValue, storeType, m_m->getDataLayout()); + assert(constStoreValue && "constant folding should succeed"); + } + } // If the LLVM type is a not a vector, we need to change the constant into an array. if (spvType->isTypeVector() && !storeType->isVectorTy()) { @@ -4478,7 +4483,8 @@ Constant *SPIRVToLLVM::transInitializer(SPIRVValue *const spvValue, Type *const // in memory. assert(initializer->getType()->isIntOrIntVectorTy(1)); assert(type->isIntOrIntVectorTy(32)); - initializer = ConstantExpr::getZExt(initializer, type); + initializer = ConstantFoldCastOperand(Instruction::ZExt, initializer, type, m_m->getDataLayout()); + assert(initializer && "constant folding should not fail on integers"); } return initializer; }