[PATCH] D24311: Implement MS _rot intrinsics
Reid Kleckner via cfe-commits
cfe-commits at lists.llvm.org
Thu Sep 8 13:51:26 PDT 2016
rnk added inline comments.
================
Comment at: lib/AST/ExprConstant.cpp:7024-7050
@@ -7023,1 +7023,29 @@
+ case Builtin::BI_rotl8:
+ case Builtin::BI_rotl16:
+ case Builtin::BI_rotl:
+ case Builtin::BI_lrotl:
+ case Builtin::BI_rotl64: {
+ APSInt Val, Shift;
+ if (!EvaluateInteger(E->getArg(0), Val, Info) ||
+ !EvaluateInteger(E->getArg(1), Shift, Info))
+ return false;
+
+ APSInt BitWidth(llvm::APInt(32, Val.getBitWidth()));
+ return Success(Val.rotl(Shift % BitWidth), E);
+ }
+
+ case Builtin::BI_rotr8:
+ case Builtin::BI_rotr16:
+ case Builtin::BI_rotr:
+ case Builtin::BI_lrotr:
+ case Builtin::BI_rotr64: {
+ APSInt Val, Shift;
+ if (!EvaluateInteger(E->getArg(0), Val, Info) ||
+ !EvaluateInteger(E->getArg(1), Shift, Info))
+ return false;
+
+ APSInt BitWidth(llvm::APInt(32, Val.getBitWidth()));
+ return Success(Val.rotr(Shift % BitWidth), E);
+ }
+
----------------
majnemer wrote:
> agutowski wrote:
> > majnemer wrote:
> > > Any reason why we need this?
> > >
> > > Given:
> > > #include <intrin.h>
> > >
> > > constexpr int x = _rotl8(1, 2);
> > >
> > > MSVC 2015 reports:
> > > error C2131: expression did not evaluate to a constant
> > Hm, I don't know. Is there any reason why we shouldn't do this? I mean, I just had the feeling that if we can evaluate something during compilation time, we should to it.
> The best reason I can think of is that it allows people to use a Microsoft-specific intrinsic in ways which won't compile with Microsoft's compiler.
Yeah, I agree, we should drop the constexpr part of this. The use case for these intrinsics is really to get at the x86 instructions.
https://reviews.llvm.org/D24311
More information about the cfe-commits
mailing list