[llvm-branch-commits] [cfe-branch] r340289 - Merging r340048:

Hans Wennborg via llvm-branch-commits llvm-branch-commits at lists.llvm.org
Tue Aug 21 08:56:49 PDT 2018


Author: hans
Date: Tue Aug 21 08:56:49 2018
New Revision: 340289

URL: http://llvm.org/viewvc/llvm-project?rev=340289&view=rev
Log:
Merging r340048:
------------------------------------------------------------------------
r340048 | nico | 2018-08-17 19:19:06 +0200 (Fri, 17 Aug 2018) | 10 lines

Make __shiftleft128 / __shiftright128 real compiler built-ins.

r337619 added __shiftleft128 / __shiftright128 as functions in intrin.h.
Microsoft's STL plans on using these functions, and they're using intrin0.h
which just has declarations of built-ins to not pull in the huge intrin.h
header in the standard library headers. That requires that these functions are
real built-ins.

https://reviews.llvm.org/D50907

------------------------------------------------------------------------

Modified:
    cfe/branches/release_70/   (props changed)
    cfe/branches/release_70/include/clang/Basic/BuiltinsX86_64.def
    cfe/branches/release_70/lib/CodeGen/CGBuiltin.cpp
    cfe/branches/release_70/lib/Headers/intrin.h   (contents, props changed)
    cfe/branches/release_70/test/CodeGen/ms-x86-intrinsics.c
    cfe/branches/release_70/test/Headers/ms-intrin.cpp

Propchange: cfe/branches/release_70/
------------------------------------------------------------------------------
--- svn:mergeinfo (original)
+++ svn:mergeinfo Tue Aug 21 08:56:49 2018
@@ -1,4 +1,4 @@
 /cfe/branches/type-system-rewrite:134693-134817
-/cfe/trunk:338552-338553,338602,338627,338749,338934,338942,339074,339128,339170,339210,339264,339281,339317,339428,339494,339597,339603,340079,340101
+/cfe/trunk:338552-338553,338602,338627,338749,338934,338942,339074,339128,339170,339210,339264,339281,339317,339428,339494,339597,339603,340048,340079,340101
 /cfe/trunk/test:170344
 /cfe/trunk/test/SemaTemplate:126920

Modified: cfe/branches/release_70/include/clang/Basic/BuiltinsX86_64.def
URL: http://llvm.org/viewvc/llvm-project/cfe/branches/release_70/include/clang/Basic/BuiltinsX86_64.def?rev=340289&r1=340288&r2=340289&view=diff
==============================================================================
--- cfe/branches/release_70/include/clang/Basic/BuiltinsX86_64.def (original)
+++ cfe/branches/release_70/include/clang/Basic/BuiltinsX86_64.def Tue Aug 21 08:56:49 2018
@@ -31,6 +31,8 @@ TARGET_HEADER_BUILTIN(_mul128, "LLiLLiLL
 TARGET_HEADER_BUILTIN(_umul128, "ULLiULLiULLiULLi*", "nch",   "intrin.h", ALL_MS_LANGUAGES, "")
 
 TARGET_HEADER_BUILTIN(__faststorefence, "v", "nh", "intrin.h", ALL_MS_LANGUAGES, "")
+TARGET_HEADER_BUILTIN(__shiftleft128, "ULLiULLiULLiUc", "nch", "intrin.h", ALL_MS_LANGUAGES, "")
+TARGET_HEADER_BUILTIN(__shiftright128, "ULLiULLiULLiUc", "nch", "intrin.h", ALL_MS_LANGUAGES, "")
 
 TARGET_HEADER_BUILTIN(_InterlockedAnd64,         "LLiLLiD*LLi", "nh", "intrin.h", ALL_MS_LANGUAGES, "")
 TARGET_HEADER_BUILTIN(_InterlockedDecrement64,   "LLiLLiD*",    "nh", "intrin.h", ALL_MS_LANGUAGES, "")

Modified: cfe/branches/release_70/lib/CodeGen/CGBuiltin.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/branches/release_70/lib/CodeGen/CGBuiltin.cpp?rev=340289&r1=340288&r2=340289&view=diff
==============================================================================
--- cfe/branches/release_70/lib/CodeGen/CGBuiltin.cpp (original)
+++ cfe/branches/release_70/lib/CodeGen/CGBuiltin.cpp Tue Aug 21 08:56:49 2018
@@ -10361,6 +10361,27 @@ Value *CodeGenFunction::EmitX86BuiltinEx
     return Builder.CreateFence(llvm::AtomicOrdering::SequentiallyConsistent,
                                llvm::SyncScope::System);
   }
+  case X86::BI__shiftleft128:
+  case X86::BI__shiftright128: {
+    // FIXME: Once fshl/fshr no longer add an unneeded and and cmov, do this:
+    // llvm::Function *F = CGM.getIntrinsic(
+    //   BuiltinID == X86::BI__shiftleft128 ? Intrinsic::fshl : Intrinsic::fshr,
+    //   Int64Ty);
+    // Ops[2] = Builder.CreateZExt(Ops[2], Int64Ty);
+    // return Builder.CreateCall(F, Ops);
+    llvm::Type *Int128Ty = Builder.getInt128Ty();
+    Value *Val = Builder.CreateOr(
+        Builder.CreateShl(Builder.CreateZExt(Ops[1], Int128Ty), 64),
+        Builder.CreateZExt(Ops[0], Int128Ty));
+    Value *Amt = Builder.CreateAnd(Builder.CreateZExt(Ops[2], Int128Ty),
+                                   llvm::ConstantInt::get(Int128Ty, 0x3f));
+    Value *Res;
+    if (BuiltinID == X86::BI__shiftleft128)
+      Res = Builder.CreateLShr(Builder.CreateShl(Val, Amt), 64);
+    else
+      Res = Builder.CreateLShr(Val, Amt);
+    return Builder.CreateTrunc(Res, Int64Ty);
+  }
   case X86::BI_ReadWriteBarrier:
   case X86::BI_ReadBarrier:
   case X86::BI_WriteBarrier: {

Modified: cfe/branches/release_70/lib/Headers/intrin.h
URL: http://llvm.org/viewvc/llvm-project/cfe/branches/release_70/lib/Headers/intrin.h?rev=340289&r1=340288&r2=340289&view=diff
==============================================================================
--- cfe/branches/release_70/lib/Headers/intrin.h (original)
+++ cfe/branches/release_70/lib/Headers/intrin.h Tue Aug 21 08:56:49 2018
@@ -863,20 +863,6 @@ __nop(void) {
   __asm__ volatile ("nop");
 }
 #endif
-#if defined(__x86_64__)
-static __inline__ unsigned __int64 __DEFAULT_FN_ATTRS
-__shiftleft128(unsigned __int64 __l, unsigned __int64 __h, unsigned char __d) {
-  unsigned __int128 __val = ((unsigned __int128)__h << 64) | __l;
-  unsigned __int128 __res = __val << (__d & 63);
-  return (unsigned __int64)(__res >> 64);
-}
-static __inline__ unsigned __int64 __DEFAULT_FN_ATTRS
-__shiftright128(unsigned __int64 __l, unsigned __int64 __h, unsigned char __d) {
-  unsigned __int128 __val = ((unsigned __int128)__h << 64) | __l;
-  unsigned __int128 __res = __val >> (__d & 63);
-  return (unsigned __int64)__res;
-}
-#endif
 
 /*----------------------------------------------------------------------------*\
 |* Privileged intrinsics

Propchange: cfe/branches/release_70/lib/Headers/intrin.h
------------------------------------------------------------------------------
--- svn:mergeinfo (original)
+++ svn:mergeinfo Tue Aug 21 08:56:49 2018
@@ -1,3 +1,4 @@
 /cfe/branches/type-system-rewrite/lib/Headers/Intrin.h:134693-134817
+/cfe/trunk/lib/Headers/intrin.h:340048
 /cfe/trunk/test/SemaTemplate/lib/Headers/Intrin.h:126920
 /cfe/trunk/test/lib/Headers/Intrin.h:170344

Modified: cfe/branches/release_70/test/CodeGen/ms-x86-intrinsics.c
URL: http://llvm.org/viewvc/llvm-project/cfe/branches/release_70/test/CodeGen/ms-x86-intrinsics.c?rev=340289&r1=340288&r2=340289&view=diff
==============================================================================
--- cfe/branches/release_70/test/CodeGen/ms-x86-intrinsics.c (original)
+++ cfe/branches/release_70/test/CodeGen/ms-x86-intrinsics.c Tue Aug 21 08:56:49 2018
@@ -130,4 +130,34 @@ unsigned __int64 test_umul128(unsigned _
 // CHECK-X64: = mul nuw i128 %
 // CHECK-X64: store i64 %
 // CHECK-X64: ret i64 %
-#endif
+
+unsigned __int64 test__shiftleft128(unsigned __int64 l, unsigned __int64 h,
+                                    unsigned char d) {
+  return __shiftleft128(l, h, d);
+}
+// CHECK-X64-LABEL: define dso_local i64 @test__shiftleft128(i64 %l, i64 %h, i8 %d)
+// CHECK-X64  = zext i64 %h to i128
+// CHECK-X64  = shl nuw i128 %0, 64
+// CHECK-X64  = zext i64 %l to i128
+// CHECK-X64  = or i128 %1, %2
+// CHECK-X64  = and i8 %d, 63
+// CHECK-X64  = shl i128 %
+// CHECK-X64  = lshr i128 %
+// CHECK-X64  = trunc i128 %
+// CHECK-X64  ret i64 %
+
+unsigned __int64 test__shiftright128(unsigned __int64 l, unsigned __int64 h,
+                                     unsigned char d) {
+  return __shiftright128(l, h, d);
+}
+// CHECK-X64-LABEL: define dso_local i64 @test__shiftright128(i64 %l, i64 %h, i8 %d)
+// CHECK-X64  = zext i64 %h to i128
+// CHECK-X64  = shl nuw i128 %
+// CHECK-X64  = zext i64 %l to i128
+// CHECK-X64  = or i128 %
+// CHECK-X64  = and i8 %d, 63
+// CHECK-X64  = lshr i128 %
+// CHECK-X64  = trunc i128 %
+// CHECK-X64  ret i64 %
+
+#endif // defined(__x86_64__)

Modified: cfe/branches/release_70/test/Headers/ms-intrin.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/branches/release_70/test/Headers/ms-intrin.cpp?rev=340289&r1=340288&r2=340289&view=diff
==============================================================================
--- cfe/branches/release_70/test/Headers/ms-intrin.cpp (original)
+++ cfe/branches/release_70/test/Headers/ms-intrin.cpp Tue Aug 21 08:56:49 2018
@@ -42,8 +42,6 @@ void f() {
   __stosw(0, 0, 0);
 
 #ifdef _M_X64
-  __shiftleft128(1, 2, 3);
-  __shiftright128(1, 2, 3);
   __movsq(0, 0, 0);
   __stosq(0, 0, 0);
 #endif




More information about the llvm-branch-commits mailing list