[PATCH] D24311: Implement MS _rot intrinsics

David Majnemer via cfe-commits cfe-commits at lists.llvm.org
Thu Sep 8 11:29:33 PDT 2016


majnemer 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);
+  }
+
----------------
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.


https://reviews.llvm.org/D24311





More information about the cfe-commits mailing list