@@ -76,15 +76,18 @@ class SPIRVLegalizePointerCast : public FunctionPass {
76
76
FixedVectorType *TargetType, Value *Source) {
77
77
assert (TargetType->getNumElements () <= SourceType->getNumElements ());
78
78
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
+ }
83
86
84
87
SmallVector<int > Mask (/* Size= */ TargetType->getNumElements ());
85
88
for (unsigned I = 0 ; I < TargetType->getNumElements (); ++I)
86
89
Mask[I] = I;
87
- Value *Output = B.CreateShuffleVector (AssignType, AssignType , Mask);
90
+ Value *Output = B.CreateShuffleVector (AssignValue, AssignValue , Mask);
88
91
buildAssignType (B, TargetType, Output);
89
92
return Output;
90
93
}
@@ -136,7 +139,9 @@ class SPIRVLegalizePointerCast : public FunctionPass {
136
139
OriginalOperand, LI);
137
140
}
138
141
// Destination is a smaller vector than source.
142
+ // or different vector type.
139
143
// - float3 v3 = vector4;
144
+ // - float4 v2 = int4;
140
145
else if (SVT && DVT)
141
146
Output = loadVectorFromVector (B, SVT, DVT, OriginalOperand);
142
147
// Destination is the scalar type stored at the start of an aggregate.
0 commit comments