r340048 - Make __shiftleft128 / __shiftright128 real compiler built-ins.

Hans Wennborg via cfe-commits cfe-commits at lists.llvm.org
Tue Aug 21 08:57:40 PDT 2018


Merged to 7.0 in r340289.

On Fri, Aug 17, 2018 at 10:19 AM, Nico Weber via cfe-commits
<cfe-commits at lists.llvm.org> wrote:
> Author: nico
> Date: Fri Aug 17 10:19:06 2018
> New Revision: 340048
>
> URL: http://llvm.org/viewvc/llvm-project?rev=340048&view=rev
> Log:
> 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/trunk/include/clang/Basic/BuiltinsX86_64.def
>     cfe/trunk/lib/CodeGen/CGBuiltin.cpp
>     cfe/trunk/lib/Headers/intrin.h
>     cfe/trunk/test/CodeGen/ms-x86-intrinsics.c
>     cfe/trunk/test/Headers/ms-intrin.cpp
>
> Modified: cfe/trunk/include/clang/Basic/BuiltinsX86_64.def
> URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/BuiltinsX86_64.def?rev=340048&r1=340047&r2=340048&view=diff
> ==============================================================================
> --- cfe/trunk/include/clang/Basic/BuiltinsX86_64.def (original)
> +++ cfe/trunk/include/clang/Basic/BuiltinsX86_64.def Fri Aug 17 10:19:06 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/trunk/lib/CodeGen/CGBuiltin.cpp
> URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGBuiltin.cpp?rev=340048&r1=340047&r2=340048&view=diff
> ==============================================================================
> --- cfe/trunk/lib/CodeGen/CGBuiltin.cpp (original)
> +++ cfe/trunk/lib/CodeGen/CGBuiltin.cpp Fri Aug 17 10:19:06 2018
> @@ -10440,6 +10440,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/trunk/lib/Headers/intrin.h
> URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Headers/intrin.h?rev=340048&r1=340047&r2=340048&view=diff
> ==============================================================================
> --- cfe/trunk/lib/Headers/intrin.h (original)
> +++ cfe/trunk/lib/Headers/intrin.h Fri Aug 17 10:19:06 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
>
> Modified: cfe/trunk/test/CodeGen/ms-x86-intrinsics.c
> URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGen/ms-x86-intrinsics.c?rev=340048&r1=340047&r2=340048&view=diff
> ==============================================================================
> --- cfe/trunk/test/CodeGen/ms-x86-intrinsics.c (original)
> +++ cfe/trunk/test/CodeGen/ms-x86-intrinsics.c Fri Aug 17 10:19:06 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/trunk/test/Headers/ms-intrin.cpp
> URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Headers/ms-intrin.cpp?rev=340048&r1=340047&r2=340048&view=diff
> ==============================================================================
> --- cfe/trunk/test/Headers/ms-intrin.cpp (original)
> +++ cfe/trunk/test/Headers/ms-intrin.cpp Fri Aug 17 10:19:06 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
>
>
> _______________________________________________
> cfe-commits mailing list
> cfe-commits at lists.llvm.org
> http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


More information about the cfe-commits mailing list