[llvm] 4421b24 - [SPIRV] fix build with clang and use PoisonValue instead of UndefValue

Ilia Diachkov via llvm-commits llvm-commits at lists.llvm.org
Thu Sep 22 01:06:29 PDT 2022


Author: Ilia Diachkov
Date: 2022-09-22T11:49:54+03:00
New Revision: 4421b24fe2c856f8f75216fa3d82999db9f69d42

URL: https://github.com/llvm/llvm-project/commit/4421b24fe2c856f8f75216fa3d82999db9f69d42
DIFF: https://github.com/llvm/llvm-project/commit/4421b24fe2c856f8f75216fa3d82999db9f69d42.diff

LOG: [SPIRV] fix build with clang and use PoisonValue instead of UndefValue

The patch fixes the SPIRV backend build using clang. It also replaces
UndefValue with PoisonValue in SPIRVRegularizer.cpp.

Fixes: #57773

Differential Revision: https://reviews.llvm.org/D134071

Added: 
    

Modified: 
    llvm/lib/Target/SPIRV/SPIRVBuiltins.cpp
    llvm/lib/Target/SPIRV/SPIRVRegularizer.cpp

Removed: 
    


################################################################################
diff  --git a/llvm/lib/Target/SPIRV/SPIRVBuiltins.cpp b/llvm/lib/Target/SPIRV/SPIRVBuiltins.cpp
index c4ccfee7aaa5e..0b838ab1e8add 100644
--- a/llvm/lib/Target/SPIRV/SPIRVBuiltins.cpp
+++ b/llvm/lib/Target/SPIRV/SPIRVBuiltins.cpp
@@ -1795,7 +1795,7 @@ static SPIRVType *getSampledImageType(const StructType *OpaqueType,
 
 namespace SPIRV {
 SPIRVType *lowerBuiltinType(const StructType *OpaqueType,
-                            AccessQualifier::AccessQualifier AccessQual,
+                            SPIRV::AccessQualifier::AccessQualifier AccessQual,
                             MachineIRBuilder &MIRBuilder,
                             SPIRVGlobalRegistry *GR) {
   assert(OpaqueType->hasName() &&

diff  --git a/llvm/lib/Target/SPIRV/SPIRVRegularizer.cpp b/llvm/lib/Target/SPIRV/SPIRVRegularizer.cpp
index d7c66addf25cb..69681fd2a54ed 100644
--- a/llvm/lib/Target/SPIRV/SPIRVRegularizer.cpp
+++ b/llvm/lib/Target/SPIRV/SPIRVRegularizer.cpp
@@ -220,13 +220,25 @@ void SPIRVRegularizer::visitCallScalToVec(CallInst *CI, StringRef MangledName,
   }
   assert(NewF);
 
+  // This produces an instruction sequence that implements a splat of
+  // CI->getOperand(1) to a vector Arg0Ty. However, we use InsertElementInst
+  // and ShuffleVectorInst to generate the same code as the SPIR-V translator.
+  // For instance (transcoding/OpMin.ll), this call
+  //   call spir_func <2 x i32> @_Z3minDv2_ii(<2 x i32> <i32 1, i32 10>, i32 5)
+  // is translated to
+  //    %8 = OpUndef %v2uint
+  //   %14 = OpConstantComposite %v2uint %uint_1 %uint_10
+  //   ...
+  //   %10 = OpCompositeInsert %v2uint %uint_5 %8 0
+  //   %11 = OpVectorShuffle %v2uint %10 %8 0 0
+  // %call = OpExtInst %v2uint %1 s_min %14 %11
   auto ConstInt = ConstantInt::get(IntegerType::get(CI->getContext(), 32), 0);
-  UndefValue *UndefVal = UndefValue::get(Arg0Ty);
+  PoisonValue *PVal = PoisonValue::get(Arg0Ty);
   Instruction *Inst =
-      InsertElementInst::Create(UndefVal, CI->getOperand(1), ConstInt, "", CI);
+      InsertElementInst::Create(PVal, CI->getOperand(1), ConstInt, "", CI);
   ElementCount VecElemCount = cast<VectorType>(Arg0Ty)->getElementCount();
   Constant *ConstVec = ConstantVector::getSplat(VecElemCount, ConstInt);
-  Value *NewVec = new ShuffleVectorInst(Inst, UndefVal, ConstVec, "", CI);
+  Value *NewVec = new ShuffleVectorInst(Inst, PVal, ConstVec, "", CI);
   CI->setOperand(1, NewVec);
   CI->replaceUsesOfWith(OldF, NewF);
   CI->mutateFunctionType(NewF->getFunctionType());


        


More information about the llvm-commits mailing list