@@ -427,7 +427,7 @@ Type *SPIRVEmitIntrinsics::reconstructType(Value *Op, bool UnknownElemTypeI8,
427
427
428
428
void SPIRVEmitIntrinsics::buildAssignType (IRBuilder<> &B, Type *Ty,
429
429
Value *Arg) {
430
- Value *OfType = PoisonValue::get (Ty);
430
+ Value *OfType = getNormalizedPoisonValue (Ty);
431
431
CallInst *AssignCI = nullptr ;
432
432
if (Arg->getType ()->isAggregateType () && Ty->isAggregateType () &&
433
433
allowEmitFakeUse (Arg)) {
@@ -447,6 +447,7 @@ void SPIRVEmitIntrinsics::buildAssignType(IRBuilder<> &B, Type *Ty,
447
447
448
448
void SPIRVEmitIntrinsics::buildAssignPtr (IRBuilder<> &B, Type *ElemTy,
449
449
Value *Arg) {
450
+ ElemTy = normalizeType (ElemTy);
450
451
Value *OfType = PoisonValue::get (ElemTy);
451
452
CallInst *AssignPtrTyCI = GR->findAssignPtrTypeInstr (Arg);
452
453
if (AssignPtrTyCI == nullptr ||
@@ -470,7 +471,7 @@ void SPIRVEmitIntrinsics::updateAssignType(CallInst *AssignCI, Value *Arg,
470
471
return ;
471
472
472
473
// update association with the pointee type
473
- Type *ElemTy = OfType->getType ();
474
+ Type *ElemTy = normalizeType ( OfType->getType () );
474
475
GR->addDeducedElementType (AssignCI, ElemTy);
475
476
GR->addDeducedElementType (Arg, ElemTy);
476
477
}
@@ -490,7 +491,7 @@ CallInst *SPIRVEmitIntrinsics::buildSpvPtrcast(Function *F, Value *Op,
490
491
}
491
492
Type *OpTy = Op->getType ();
492
493
SmallVector<Type *, 2 > Types = {OpTy, OpTy};
493
- SmallVector<Value *, 2 > Args = {Op, buildMD (PoisonValue::get (ElemTy)),
494
+ SmallVector<Value *, 2 > Args = {Op, buildMD (getNormalizedPoisonValue (ElemTy)),
494
495
B.getInt32 (getPointerAddressSpace (OpTy))};
495
496
CallInst *PtrCasted =
496
497
B.CreateIntrinsic (Intrinsic::spv_ptrcast, {Types}, Args);
@@ -771,7 +772,7 @@ Type *SPIRVEmitIntrinsics::deduceElementTypeHelper(
771
772
// remember the found relationship
772
773
if (Ty && !IgnoreKnownType) {
773
774
// specify nested types if needed, otherwise return unchanged
774
- GR->addDeducedElementType (I, Ty );
775
+ GR->addDeducedElementType (I, normalizeType (Ty) );
775
776
}
776
777
777
778
return Ty;
@@ -857,7 +858,7 @@ Type *SPIRVEmitIntrinsics::deduceNestedTypeHelper(
857
858
}
858
859
if (Ty != OpTy) {
859
860
Type *NewTy = VectorType::get (Ty, VecTy->getElementCount ());
860
- GR->addDeducedCompositeType (U, NewTy);
861
+ GR->addDeducedCompositeType (U, normalizeType ( NewTy) );
861
862
return NewTy;
862
863
}
863
864
}
@@ -995,6 +996,7 @@ bool SPIRVEmitIntrinsics::deduceOperandElementTypeFunctionRet(
995
996
if (KnownElemTy)
996
997
return false ;
997
998
if (Type *OpElemTy = GR->findDeducedElementType (Op)) {
999
+ OpElemTy = normalizeType (OpElemTy);
998
1000
GR->addDeducedElementType (F, OpElemTy);
999
1001
GR->addReturnType (
1000
1002
F, TypedPointerType::get (OpElemTy,
@@ -1007,7 +1009,7 @@ bool SPIRVEmitIntrinsics::deduceOperandElementTypeFunctionRet(
1007
1009
continue ;
1008
1010
if (CallInst *AssignCI = GR->findAssignPtrTypeInstr (CI)) {
1009
1011
if (Type *PrevElemTy = GR->findDeducedElementType (CI)) {
1010
- updateAssignType (AssignCI, CI, PoisonValue::get (OpElemTy));
1012
+ updateAssignType (AssignCI, CI, getNormalizedPoisonValue (OpElemTy));
1011
1013
propagateElemType (CI, PrevElemTy, VisitedSubst);
1012
1014
}
1013
1015
}
@@ -1167,11 +1169,11 @@ void SPIRVEmitIntrinsics::deduceOperandElementType(
1167
1169
Type *Ty = AskTy ? AskTy : GR->findDeducedElementType (Op);
1168
1170
if (Ty == KnownElemTy)
1169
1171
continue ;
1170
- Value *OpTyVal = PoisonValue::get (KnownElemTy);
1172
+ Value *OpTyVal = getNormalizedPoisonValue (KnownElemTy);
1171
1173
Type *OpTy = Op->getType ();
1172
1174
if (!Ty || AskTy || isUntypedPointerTy (Ty) || isTodoType (Op)) {
1173
1175
Type *PrevElemTy = GR->findDeducedElementType (Op);
1174
- GR->addDeducedElementType (Op, KnownElemTy);
1176
+ GR->addDeducedElementType (Op, normalizeType ( KnownElemTy) );
1175
1177
// check if KnownElemTy is complete
1176
1178
if (!Uncomplete)
1177
1179
eraseTodoType (Op);
@@ -1497,7 +1499,7 @@ void SPIRVEmitIntrinsics::insertAssignPtrTypeTargetExt(
1497
1499
1498
1500
// Our previous guess about the type seems to be wrong, let's update
1499
1501
// inferred type according to a new, more precise type information.
1500
- updateAssignType (AssignCI, V, PoisonValue::get (AssignedType));
1502
+ updateAssignType (AssignCI, V, getNormalizedPoisonValue (AssignedType));
1501
1503
}
1502
1504
1503
1505
void SPIRVEmitIntrinsics::replacePointerOperandWithPtrCast (
@@ -1512,7 +1514,7 @@ void SPIRVEmitIntrinsics::replacePointerOperandWithPtrCast(
1512
1514
return ;
1513
1515
1514
1516
setInsertPointSkippingPhis (B, I);
1515
- Value *ExpectedElementVal = PoisonValue::get (ExpectedElementType);
1517
+ Value *ExpectedElementVal = getNormalizedPoisonValue (ExpectedElementType);
1516
1518
MetadataAsValue *VMD = buildMD (ExpectedElementVal);
1517
1519
unsigned AddressSpace = getPointerAddressSpace (Pointer->getType ());
1518
1520
bool FirstPtrCastOrAssignPtrType = true ;
@@ -1658,7 +1660,7 @@ void SPIRVEmitIntrinsics::insertPtrCastOrAssignTypeInstr(Instruction *I,
1658
1660
if (!ElemTy) {
1659
1661
ElemTy = getPointeeTypeByCallInst (DemangledName, CalledF, OpIdx);
1660
1662
if (ElemTy) {
1661
- GR->addDeducedElementType (CalledArg, ElemTy);
1663
+ GR->addDeducedElementType (CalledArg, normalizeType ( ElemTy) );
1662
1664
} else {
1663
1665
for (User *U : CalledArg->users ()) {
1664
1666
if (Instruction *Inst = dyn_cast<Instruction>(U)) {
@@ -1709,6 +1711,11 @@ void SPIRVEmitIntrinsics::insertPtrCastOrAssignTypeInstr(Instruction *I,
1709
1711
}
1710
1712
1711
1713
Instruction *SPIRVEmitIntrinsics::visitInsertElementInst (InsertElementInst &I) {
1714
+ // If it's a <1 x Type> vector type, don't modify it. It's not a legal vector
1715
+ // type in LLT and IRTranslator will replace it by the scalar.
1716
+ if (isVector1 (I.getType ()))
1717
+ return &I;
1718
+
1712
1719
SmallVector<Type *, 4 > Types = {I.getType (), I.getOperand (0 )->getType (),
1713
1720
I.getOperand (1 )->getType (),
1714
1721
I.getOperand (2 )->getType ()};
@@ -1722,6 +1729,11 @@ Instruction *SPIRVEmitIntrinsics::visitInsertElementInst(InsertElementInst &I) {
1722
1729
1723
1730
Instruction *
1724
1731
SPIRVEmitIntrinsics::visitExtractElementInst (ExtractElementInst &I) {
1732
+ // If it's a <1 x Type> vector type, don't modify it. It's not a legal vector
1733
+ // type in LLT and IRTranslator will replace it by the scalar.
1734
+ if (isVector1 (I.getVectorOperandType ()))
1735
+ return &I;
1736
+
1725
1737
IRBuilder<> B (I.getParent ());
1726
1738
B.SetInsertPoint (&I);
1727
1739
SmallVector<Type *, 3 > Types = {I.getType (), I.getVectorOperandType (),
@@ -1989,8 +2001,9 @@ void SPIRVEmitIntrinsics::insertAssignTypeIntrs(Instruction *I,
1989
2001
Type *ElemTy = GR->findDeducedElementType (Op);
1990
2002
buildAssignPtr (B, ElemTy ? ElemTy : deduceElementType (Op, true ), Op);
1991
2003
} else {
1992
- CallInst *AssignCI = buildIntrWithMD (Intrinsic::spv_assign_type,
1993
- {OpTy}, Op, Op, {}, B);
2004
+ CallInst *AssignCI =
2005
+ buildIntrWithMD (Intrinsic::spv_assign_type, {OpTy},
2006
+ getNormalizedPoisonValue (OpTy), Op, {}, B);
1994
2007
GR->addAssignPtrTypeInstr (Op, AssignCI);
1995
2008
}
1996
2009
}
@@ -2039,7 +2052,7 @@ void SPIRVEmitIntrinsics::processInstrAfterVisit(Instruction *I,
2039
2052
Type *OpTy = Op->getType ();
2040
2053
Value *OpTyVal = Op;
2041
2054
if (OpTy->isTargetExtTy ())
2042
- OpTyVal = PoisonValue::get (OpTy);
2055
+ OpTyVal = getNormalizedPoisonValue (OpTy);
2043
2056
CallInst *NewOp =
2044
2057
buildIntrWithMD (Intrinsic::spv_track_constant,
2045
2058
{OpTy, OpTyVal->getType ()}, Op, OpTyVal, {}, B);
@@ -2050,7 +2063,7 @@ void SPIRVEmitIntrinsics::processInstrAfterVisit(Instruction *I,
2050
2063
buildAssignPtr (B, IntegerType::getInt8Ty (I->getContext ()), NewOp);
2051
2064
SmallVector<Type *, 2 > Types = {OpTy, OpTy};
2052
2065
SmallVector<Value *, 2 > Args = {
2053
- NewOp, buildMD (PoisonValue::get (OpElemTy)),
2066
+ NewOp, buildMD (getNormalizedPoisonValue (OpElemTy)),
2054
2067
B.getInt32 (getPointerAddressSpace (OpTy))};
2055
2068
CallInst *PtrCasted =
2056
2069
B.CreateIntrinsic (Intrinsic::spv_ptrcast, {Types}, Args);
@@ -2183,7 +2196,7 @@ void SPIRVEmitIntrinsics::processParamTypes(Function *F, IRBuilder<> &B) {
2183
2196
if (!ElemTy && (ElemTy = deduceFunParamElementType (F, OpIdx)) != nullptr ) {
2184
2197
if (CallInst *AssignCI = GR->findAssignPtrTypeInstr (Arg)) {
2185
2198
DenseSet<std::pair<Value *, Value *>> VisitedSubst;
2186
- updateAssignType (AssignCI, Arg, PoisonValue::get (ElemTy));
2199
+ updateAssignType (AssignCI, Arg, getNormalizedPoisonValue (ElemTy));
2187
2200
propagateElemType (Arg, IntegerType::getInt8Ty (F->getContext ()),
2188
2201
VisitedSubst);
2189
2202
} else {
@@ -2237,7 +2250,7 @@ bool SPIRVEmitIntrinsics::processFunctionPointers(Module &M) {
2237
2250
continue ;
2238
2251
if (II->getIntrinsicID () == Intrinsic::spv_assign_ptr_type ||
2239
2252
II->getIntrinsicID () == Intrinsic::spv_ptrcast) {
2240
- updateAssignType (II, &F, PoisonValue::get (FPElemTy));
2253
+ updateAssignType (II, &F, getNormalizedPoisonValue (FPElemTy));
2241
2254
break ;
2242
2255
}
2243
2256
}
@@ -2261,7 +2274,7 @@ bool SPIRVEmitIntrinsics::processFunctionPointers(Module &M) {
2261
2274
for (Function *F : Worklist) {
2262
2275
SmallVector<Value *> Args;
2263
2276
for (const auto &Arg : F->args ())
2264
- Args.push_back (PoisonValue::get (Arg.getType ()));
2277
+ Args.push_back (getNormalizedPoisonValue (Arg.getType ()));
2265
2278
IRB.CreateCall (F, Args);
2266
2279
}
2267
2280
IRB.CreateRetVoid ();
@@ -2291,7 +2304,7 @@ void SPIRVEmitIntrinsics::applyDemangledPtrArgTypes(IRBuilder<> &B) {
2291
2304
buildAssignPtr (B, ElemTy, Arg);
2292
2305
}
2293
2306
} else if (isa<Instruction>(Param)) {
2294
- GR->addDeducedElementType (Param, ElemTy);
2307
+ GR->addDeducedElementType (Param, normalizeType ( ElemTy) );
2295
2308
// insertAssignTypeIntrs() will complete buildAssignPtr()
2296
2309
} else {
2297
2310
B.SetInsertPoint (CI->getParent ()
@@ -2307,6 +2320,7 @@ void SPIRVEmitIntrinsics::applyDemangledPtrArgTypes(IRBuilder<> &B) {
2307
2320
if (!RefF || !isPointerTy (RefF->getReturnType ()) ||
2308
2321
GR->findDeducedElementType (RefF))
2309
2322
continue ;
2323
+ ElemTy = normalizeType (ElemTy);
2310
2324
GR->addDeducedElementType (RefF, ElemTy);
2311
2325
GR->addReturnType (
2312
2326
RefF, TypedPointerType::get (
0 commit comments