This is an archive of the discontinued LLVM Phabricator instance.

Add __builtin_convertvector
ClosedPublic

Authored by hfinkel on Sep 13 2013, 6:16 AM.

Details

Summary

LLVM supports applying conversion instructions to vectors of the same number of elements (fptrunc, fptosi, etc.) but currently there is no way for a Clang user to cause such instructions to be generated when using builtin vector types.

C-style casting on vectors is already defined in terms of bitcasts, and so cannot be used for these conversions as well (without leading to a very confusing set of semantics). As a result, I'd like to add this new intrinsic (patterned after the OpenCL __builtin_astype intrinsic). This will aid the creation of vector intrinsic headers that create generic IR instead of target-dependent intrinsics (in other words, this is a generic _mm_cvtepi32_ps).

Please review.

Diff Detail

Event Timeline

eli.friedman added inline comments.Sep 16 2013, 5:26 PM
include/clang/AST/Expr.h
3474

No, this should not be a CastExpr.

lib/CodeGen/CGExprScalar.cpp
1011

What if the destination type is a bool vector?

lib/Sema/SemaExpr.cpp
4489

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.

lib/Sema/TreeTransform.h
9171

It would be nice to fix this before committing.

hfinkel added inline comments.Sep 16 2013, 8:41 PM
include/clang/AST/Expr.h
3474

Okay; I copied this comment from the AsTypeExpr node, so we should probably remove it from there too.

lib/CodeGen/CGExprScalar.cpp
1011

I think bool vectors are explicitly forbidden (in r190721).

lib/Sema/SemaExpr.cpp
4489

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()) && "...");

lib/Sema/TreeTransform.h
9171

Agreed; this is another thing coped from the AsTypeExpr code. How can I test this?

hfinkel updated this revision to Unknown Object (????).Sep 17 2013, 2:39 PM

Here's an updated revision. TreeTransform support has been implemented, and conversions to boolean vectors are now handled by comparing to zero.

Thanks again!

You're missing a testcase for template instantiation.

  • Original Message -----
You're missing a testcase for template instantiation.

I added this to the bottom of the test case, is that what you mean?

+#ifdef cplusplus
+template<typename T>
+T int_toT(vector8long x) {
+ return
builtin_convertvector(x, T);
+}
+
+extern "C" {
+ vector8double int_toT_fp(vector8long x) {
+ CHECK-LABEL: @int_toT_fp
+
CHECK: sitofp <8 x i64> %{{[^ ]}} to <8 x double>
+ return int_toT<vector8double>(x);
+ }
+}
+#else
+vector8double int_toT_fp(vector8long x) {
+ return __builtin_convertvector(x, vector8double);
+}
+#endif

-Hal

http://llvm-reviews.chandlerc.com/D1677

hfinkel accepted this revision.Jul 10 2014, 8:51 PM
hfinkel added a reviewer: hfinkel.

Going to close this out...

This revision is now accepted and ready to land.Jul 10 2014, 8:51 PM
hfinkel closed this revision.Jul 10 2014, 8:51 PM

Committed r190915.