@@ -76,15 +76,18 @@ class SPIRVLegalizePointerCast : public FunctionPass {
7676 FixedVectorType *TargetType, Value *Source) {
7777 assert (TargetType->getNumElements () <= SourceType->getNumElements ());
7878 LoadInst *NewLoad = B.CreateLoad (SourceType, Source);
79- Value *AssignType = NewLoad;
80- if (TargetType->getElementType () != SourceType->getElementType ())
81- AssignType = B.CreateBitCast (NewLoad, TargetType);
82- buildAssignType (B, SourceType, AssignType);
79+ buildAssignType (B, SourceType, NewLoad);
80+ Value *AssignValue = NewLoad;
81+ if (TargetType->getElementType () != SourceType->getElementType ()) {
82+ AssignValue = B.CreateIntrinsic (Intrinsic::spv_bitcast,
83+ {TargetType, SourceType}, {NewLoad});
84+ buildAssignType (B, TargetType, AssignValue);
85+ }
8386
8487 SmallVector<int > Mask (/* Size= */ TargetType->getNumElements ());
8588 for (unsigned I = 0 ; I < TargetType->getNumElements (); ++I)
8689 Mask[I] = I;
87- Value *Output = B.CreateShuffleVector (AssignType, AssignType , Mask);
90+ Value *Output = B.CreateShuffleVector (AssignValue, AssignValue , Mask);
8891 buildAssignType (B, TargetType, Output);
8992 return Output;
9093 }
@@ -136,7 +139,9 @@ class SPIRVLegalizePointerCast : public FunctionPass {
136139 OriginalOperand, LI);
137140 }
138141 // Destination is a smaller vector than source.
142+ // or different vector type.
139143 // - float3 v3 = vector4;
144+ // - float4 v2 = int4;
140145 else if (SVT && DVT)
141146 Output = loadVectorFromVector (B, SVT, DVT, OriginalOperand);
142147 // Destination is the scalar type stored at the start of an aggregate.
0 commit comments