@@ -2064,7 +2064,8 @@ llvm::Value *CodeGenFunction::EmitToMemory(llvm::Value *Value, QualType Ty) {
20642064
20652065 if (Ty->isExtVectorBoolType ()) {
20662066 llvm::Type *StoreTy = convertTypeForLoadStore (Ty, Value->getType ());
2067- if (getLangOpts ().HLSL )
2067+ if (StoreTy->isVectorTy () && StoreTy->getScalarSizeInBits () >
2068+ Value->getType ()->getScalarSizeInBits ())
20682069 return Builder.CreateZExt (Value, StoreTy);
20692070
20702071 // Expand to the memory bit width.
@@ -2082,10 +2083,8 @@ llvm::Value *CodeGenFunction::EmitToMemory(llvm::Value *Value, QualType Ty) {
20822083// / by convertTypeForLoadStore) to its primary IR type (as returned
20832084// / by ConvertType).
20842085llvm::Value *CodeGenFunction::EmitFromMemory (llvm::Value *Value, QualType Ty) {
2085- if (Ty->isExtVectorBoolType ( )) {
2086+ if (Ty->isPackedVectorBoolType ( getContext () )) {
20862087 const auto *RawIntTy = Value->getType ();
2087- if (getLangOpts ().HLSL )
2088- return Builder.CreateTrunc (Value, ConvertType (Ty), " loadedv" );
20892088
20902089 // Bitcast iP --> <P x i1>.
20912090 auto *PaddedVecTy = llvm::FixedVectorType::get (
@@ -2097,10 +2096,10 @@ llvm::Value *CodeGenFunction::EmitFromMemory(llvm::Value *Value, QualType Ty) {
20972096 return emitBoolVecConversion (V, ValNumElems, " extractvec" );
20982097 }
20992098
2100- if (hasBooleanRepresentation (Ty) || Ty->isBitIntType ()) {
2101- llvm::Type *ResTy = ConvertType (Ty);
2099+ llvm::Type *ResTy = ConvertType (Ty);
2100+ if (hasBooleanRepresentation (Ty) || Ty->isBitIntType () ||
2101+ Ty->isExtVectorBoolType ())
21022102 return Builder.CreateTrunc (Value, ResTy, " loadedv" );
2103- }
21042103
21052104 return Value;
21062105}
@@ -2353,8 +2352,10 @@ RValue CodeGenFunction::EmitLoadOfExtVectorElementLValue(LValue LV) {
23532352
23542353 llvm::Value *Element = Builder.CreateExtractElement (Vec, Elt);
23552354
2356- if (getLangOpts ().HLSL && LV.getType ()->isBooleanType ())
2357- Element = Builder.CreateTrunc (Element, ConvertType (LV.getType ()));
2355+ llvm::Type *LVTy = ConvertType (LV.getType ());
2356+ if (Element->getType ()->getPrimitiveSizeInBits () >
2357+ LVTy->getPrimitiveSizeInBits ())
2358+ Element = Builder.CreateTrunc (Element, LVTy);
23582359
23592360 return RValue::get (Element);
23602361 }
@@ -2368,8 +2369,8 @@ RValue CodeGenFunction::EmitLoadOfExtVectorElementLValue(LValue LV) {
23682369
23692370 Vec = Builder.CreateShuffleVector (Vec, Mask);
23702371
2371- if (getLangOpts (). HLSL && LV.getType ()->isExtVectorBoolType ())
2372- Vec = EmitFromMemory (Vec, LV.getType ());
2372+ if (LV.getType ()->isExtVectorBoolType ())
2373+ Vec = Builder. CreateTrunc (Vec, ConvertType ( LV.getType ()), " truncv " );
23732374
23742375 return RValue::get (Vec);
23752376}
@@ -2424,11 +2425,12 @@ void CodeGenFunction::EmitStoreThroughLValue(RValue Src, LValue Dst,
24242425 // Read/modify/write the vector, inserting the new element.
24252426 llvm::Value *Vec = Builder.CreateLoad (Dst.getVectorAddress (),
24262427 Dst.isVolatileQualified ());
2427- llvm::Type *OldVecTy = Vec->getType ();
2428- if ( getLangOpts (). HLSL && Dst. getType ()-> isExtVectorBoolType ())
2428+ llvm::Type *VecTy = Vec->getType ();
2429+ llvm::Value *SrcVal = Src. getScalarVal ();
24292430
2430- Vec =
2431- Builder.CreateTrunc (Vec, ConvertType (Dst.getType ()), " truncboolv" );
2431+ if (SrcVal->getType ()->getPrimitiveSizeInBits () <
2432+ VecTy->getScalarSizeInBits ())
2433+ SrcVal = Builder.CreateZExt (SrcVal, VecTy->getScalarType ());
24322434
24332435 auto *IRStoreTy = dyn_cast<llvm::IntegerType>(Vec->getType ());
24342436 if (IRStoreTy) {
@@ -2437,16 +2439,13 @@ void CodeGenFunction::EmitStoreThroughLValue(RValue Src, LValue Dst,
24372439 Vec = Builder.CreateBitCast (Vec, IRVecTy);
24382440 // iN --> <N x i1>.
24392441 }
2440- Vec = Builder.CreateInsertElement (Vec, Src. getScalarVal (),
2441- Dst. getVectorIdx (), " vecins" );
2442+ Vec = Builder.CreateInsertElement (Vec, SrcVal, Dst. getVectorIdx (),
2443+ " vecins" );
24422444 if (IRStoreTy) {
24432445 // <N x i1> --> <iN>.
24442446 Vec = Builder.CreateBitCast (Vec, IRStoreTy);
24452447 }
24462448
2447- if (getLangOpts ().HLSL && Dst.getType ()->isExtVectorBoolType ())
2448- Vec = Builder.CreateZExt (Vec, OldVecTy);
2449-
24502449 Builder.CreateStore (Vec, Dst.getVectorAddress (),
24512450 Dst.isVolatileQualified ());
24522451 return ;
@@ -2643,14 +2642,13 @@ void CodeGenFunction::EmitStoreThroughExtVectorComponentLValue(RValue Src,
26432642 // This access turns into a read/modify/write of the vector. Load the input
26442643 // value now.
26452644 llvm::Value *Vec = Builder.CreateLoad (DstAddr, Dst.isVolatileQualified ());
2645+ llvm::Type *VecTy = Vec->getType ();
26462646 const llvm::Constant *Elts = Dst.getExtVectorElts ();
26472647
2648- llvm::Value *SrcVal = Src.getScalarVal ();
2649-
26502648 if (const VectorType *VTy = Dst.getType ()->getAs <VectorType>()) {
26512649 unsigned NumSrcElts = VTy->getNumElements ();
26522650 unsigned NumDstElts =
2653- cast<llvm::FixedVectorType>(Vec-> getType () )->getNumElements ();
2651+ cast<llvm::FixedVectorType>(VecTy )->getNumElements ();
26542652 if (NumDstElts == NumSrcElts) {
26552653 // Use shuffle vector is the src and destination are the same number of
26562654 // elements and restore the vector mask since it is on the side it will be
@@ -2659,6 +2657,10 @@ void CodeGenFunction::EmitStoreThroughExtVectorComponentLValue(RValue Src,
26592657 for (unsigned i = 0 ; i != NumSrcElts; ++i)
26602658 Mask[getAccessedFieldNo (i, Elts)] = i;
26612659
2660+ llvm::Value *SrcVal = Src.getScalarVal ();
2661+ if (VecTy->getScalarSizeInBits () > SrcVal->getType ()->getScalarSizeInBits ())
2662+ SrcVal = Builder.CreateZExt (SrcVal, VecTy);
2663+
26622664 Vec = Builder.CreateShuffleVector (SrcVal, Mask);
26632665 } else if (NumDstElts > NumSrcElts) {
26642666 // Extended the source vector to the same length and then shuffle it
@@ -2669,7 +2671,7 @@ void CodeGenFunction::EmitStoreThroughExtVectorComponentLValue(RValue Src,
26692671 for (unsigned i = 0 ; i != NumSrcElts; ++i)
26702672 ExtMask.push_back (i);
26712673 ExtMask.resize (NumDstElts, -1 );
2672- llvm::Value *ExtSrcVal = Builder.CreateShuffleVector (SrcVal , ExtMask);
2674+ llvm::Value *ExtSrcVal = Builder.CreateShuffleVector (Src. getScalarVal () , ExtMask);
26732675 // build identity
26742676 SmallVector<int , 4 > Mask;
26752677 for (unsigned i = 0 ; i != NumDstElts; ++i)
@@ -2694,6 +2696,11 @@ void CodeGenFunction::EmitStoreThroughExtVectorComponentLValue(RValue Src,
26942696 // be updating one element.
26952697 unsigned InIdx = getAccessedFieldNo (0 , Elts);
26962698 llvm::Value *Elt = llvm::ConstantInt::get (SizeTy, InIdx);
2699+
2700+ llvm::Value *SrcVal = Src.getScalarVal ();
2701+ if (VecTy->getScalarSizeInBits () > SrcVal->getType ()->getScalarSizeInBits ())
2702+ SrcVal = Builder.CreateZExt (SrcVal, VecTy->getScalarType ());
2703+
26972704 Vec = Builder.CreateInsertElement (Vec, SrcVal, Elt);
26982705 }
26992706
@@ -4718,12 +4725,11 @@ EmitExtVectorElementExpr(const ExtVectorElementExpr *E) {
47184725
47194726 // Store the vector to memory (because LValue wants an address).
47204727 Address VecMem = CreateMemTemp (E->getBase ()->getType ());
4721- // To be consistent need to zero extend an hlsl boolean vector to store it
4722- // back to memory
4728+ // need to zero extend an hlsl boolean vector to store it back to memory
47234729 QualType Ty = E->getBase ()->getType ();
4724- if (Ty-> isExtVectorBoolType () && getLangOpts (). HLSL )
4725- Vec =
4726- Builder.CreateZExt (Vec, convertTypeForLoadStore (Ty, Vec-> getType ()) );
4730+ llvm::Type *LTy = convertTypeForLoadStore (Ty, Vec-> getType ());
4731+ if (LTy-> getScalarSizeInBits () > Vec-> getType ()-> getScalarSizeInBits ())
4732+ Vec = Builder.CreateZExt (Vec, LTy );
47274733 Builder.CreateStore (Vec, VecMem);
47284734 Base = MakeAddrLValue (VecMem, Ty, AlignmentSource::Decl);
47294735 }
0 commit comments