@@ -151,6 +151,9 @@ class ScalarExprEmitter
151
151
Value *EmitScalarConversion (Value *Src, QualType SrcTy, QualType DstTy,
152
152
SourceLocation Loc);
153
153
154
+ Value *EmitScalarConversion (Value *Src, QualType SrcTy, QualType DstTy,
155
+ SourceLocation Loc, bool TreatBooleanAsSigned);
156
+
154
157
// / Emit a conversion from the specified complex type to the specified
155
158
// / destination type, where the destination type is an LLVM scalar type.
156
159
Value *EmitComplexToScalarConversion (CodeGenFunction::ComplexPairTy Src,
@@ -733,6 +736,13 @@ void ScalarExprEmitter::EmitFloatConversionCheck(
733
736
Value *ScalarExprEmitter::EmitScalarConversion (Value *Src, QualType SrcType,
734
737
QualType DstType,
735
738
SourceLocation Loc) {
739
+ return EmitScalarConversion (Src, SrcType, DstType, Loc, false );
740
+ }
741
+
742
+ Value *ScalarExprEmitter::EmitScalarConversion (Value *Src, QualType SrcType,
743
+ QualType DstType,
744
+ SourceLocation Loc,
745
+ bool TreatBooleanAsSigned) {
736
746
SrcType = CGF.getContext ().getCanonicalType (SrcType);
737
747
DstType = CGF.getContext ().getCanonicalType (DstType);
738
748
if (SrcType == DstType) return Src;
@@ -807,7 +817,8 @@ Value *ScalarExprEmitter::EmitScalarConversion(Value *Src, QualType SrcType,
807
817
if (DstType->isExtVectorType () && !SrcType->isVectorType ()) {
808
818
// Cast the scalar to element type
809
819
QualType EltTy = DstType->getAs <ExtVectorType>()->getElementType ();
810
- llvm::Value *Elt = EmitScalarConversion (Src, SrcType, EltTy, Loc);
820
+ llvm::Value *Elt = EmitScalarConversion (
821
+ Src, SrcType, EltTy, Loc, CGF.getContext ().getLangOpts ().OpenCL );
811
822
812
823
// Splat the element across to all elements
813
824
unsigned NumElements = cast<llvm::VectorType>(DstTy)->getNumElements ();
@@ -847,6 +858,9 @@ Value *ScalarExprEmitter::EmitScalarConversion(Value *Src, QualType SrcType,
847
858
848
859
if (isa<llvm::IntegerType>(SrcTy)) {
849
860
bool InputSigned = SrcType->isSignedIntegerOrEnumerationType ();
861
+ if (SrcType->isBooleanType () && TreatBooleanAsSigned) {
862
+ InputSigned = true ;
863
+ }
850
864
if (isa<llvm::IntegerType>(DstTy))
851
865
Res = Builder.CreateIntCast (Src, DstTy, InputSigned, " conv" );
852
866
else if (InputSigned)
@@ -1531,10 +1545,14 @@ Value *ScalarExprEmitter::VisitCastExpr(CastExpr *CE) {
1531
1545
}
1532
1546
case CK_VectorSplat: {
1533
1547
llvm::Type *DstTy = ConvertType (DestTy);
1534
- Value *Elt = Visit (const_cast <Expr*>(E));
1535
- Elt = EmitScalarConversion (Elt, E->getType (),
1548
+ // Need an IgnoreImpCasts here as by default a boolean will be promoted to
1549
+ // an int, which will not perform the sign extension, so if we know we are
1550
+ // going to cast to a vector we have to strip the implicit cast off.
1551
+ Value *Elt = Visit (const_cast <Expr*>(E->IgnoreImpCasts ()));
1552
+ Elt = EmitScalarConversion (Elt, E->IgnoreImpCasts ()->getType (),
1536
1553
DestTy->getAs <VectorType>()->getElementType (),
1537
- CE->getExprLoc ());
1554
+ CE->getExprLoc (),
1555
+ CGF.getContext ().getLangOpts ().OpenCL );
1538
1556
1539
1557
// Splat the element across to all elements
1540
1558
unsigned NumElements = cast<llvm::VectorType>(DstTy)->getNumElements ();
0 commit comments