[PATCH] Add __builtin_convertvector

Hal Finkel hfinkel at anl.gov
Tue Sep 17 14:02:25 PDT 2013


----- Original Message -----
> 
> On Mon, Sep 16, 2013 at 8:41 PM, hfinkel at anl.gov < hfinkel at anl.gov >
> wrote:
> 
> ================
> Comment at: include/clang/AST/Expr.h:3474
> @@ +3473,3 @@
> +/// vector type of the same arity.
> +class ConvertVectorExpr : public Expr { // Should this be an
> ExplicitCastExpr?
> +private:
> ----------------
> 
> Eli Friedman wrote:
> > No, this should not be a CastExpr.
> Okay; I copied this comment from the AsTypeExpr node, so we should
> probably remove it from there too.
> 
> 
> 
> Okay.
> 
> 
> 
> 
> ================
> Comment at: lib/CodeGen/CGExprScalar.cpp:1011
> @@ +1010,3 @@
> + Res = Builder.CreateIntCast(Src, DstTy, InputSigned, "conv");
> + else if (InputSigned)
> + Res = Builder.CreateSIToFP(Src, DstTy, "conv");
> ----------------
> 
> Eli Friedman wrote:
> > What if the destination type is a bool vector?
> I think bool vectors are explicitly forbidden (in r190721).
> 
> 
> 
> You can still use the ext_vector_type attribute to get one.

Ah, thanks! The code generator seems to quite happily produce (and the IR validator accepts):

%conv = fptoui <8 x float> %0 to <8 x i1>

and:

%conv = trunc <8 x i16> %0 to <8 x i1>

will that be sufficient, do we need to do something special? Would it be better to explicitly compare against zero?

> 
> 
> 
> 
> ================
> Comment at: lib/Sema/SemaExpr.cpp:4489
> @@ +4488,3 @@
> + << E->getSourceRange());
> +
> + return Owned(new (Context) ConvertVectorExpr(E, DstTy, VK, OK,
> BuiltinLoc,
> ----------------
> 
> Eli Friedman wrote:
> > You might want to be careful exactly what vector types we accept
> > here... but I can't think of anything you actually need to check
> > for, so maybe not.
> I *think* that everything relevant is checked in
> Sema::BuildExtVectorType and HandleVectorSizeAttr (in SemaType.cpp),
> and so checking that we have a vector type should be sufficient.
> 
> I could add an assert here just to be on the safe side; something
> like assert(Ty->isBuiltinType() && !Ty->isBooleanType() &&
> (Ty->isIntegerType() || Ty->->isRealFloatingType()) && "...");
> 
> 
> 
> Okay.
> 
> 
> 
> 
> ================
> Comment at: lib/Sema/TreeTransform.h:9171
> @@ +9170,3 @@
> + llvm_unreachable("Cannot transform convertVector expressions yet");
> +}
> +
> ----------------
> 
> Eli Friedman wrote:
> > It would be nice to fix this before committing.
> Agreed; this is another thing coped from the AsTypeExpr code. How can
> I test this?
> 
> 
> 
> 
> This ought to trigger it:
> 
> 
> typedef int int_v4 __attribute__((vector_size(16)));
> typedef float float_v4 __attribute__((vector_size(16)));
> template<typename T> T f(int_v4 x) { return
> __builtin_convertvector(x, T); } float_v4 g(int_v4 x) { return
> f<float_v4>(x); }
> 

Yep; that does it. I think that I have the implementation figured out; I'll post an updated patch shortly.

Thanks again,
Hal

> 
> -Eli

-- 
Hal Finkel
Assistant Computational Scientist
Leadership Computing Facility
Argonne National Laboratory



More information about the cfe-commits mailing list