This is an archive of the discontinued LLVM Phabricator instance.

Make __shiftleft128 / __shiftright128 real compiler built-ins.
ClosedPublic

Authored by thakis on Aug 17 2018, 9:53 AM.

Details

Reviewers
rnk
craig.topper
Summary

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.

Diff Detail

Event Timeline

thakis created this revision.Aug 17 2018, 9:53 AM

(I tried using funnelshift for this as mentioned in the FIXME, but it looks like it still produces a bunch of unnecessary code if the shift amount isn't constant.)

Oh, and I verified that this still gets compiled to shld / shrd:

Nicos-MacBook-Pro:llvm-mono thakis$ cat test.c
#include <intrin.h>

unsigned __int64 test__shiftleft128(unsigned __int64 l, unsigned __int64 h,
                                    unsigned char d) {
  return __shiftleft128(l, h, d);
}

unsigned __int64 test__shiftright128(unsigned __int64 l, unsigned __int64 h,
                                     unsigned char d) {
  return __shiftright128(l, h, d);
}
Nicos-MacBook-Pro:llvm-mono thakis$ ./clang-cl.sh /O2 /c test.c   /FA ; cat test.asm
	.text
	.intel_syntax noprefix
	.def	 test__shiftleft128;
	.scl	2;
	.type	32;
	.endef
	.section	.text,"xr",one_only,test__shiftleft128
	.globl	test__shiftleft128      # -- Begin function test__shiftleft128
	.p2align	4, 0x90
test__shiftleft128:                     # @test__shiftleft128
# %bb.0:                                # %entry
	mov	rax, rcx
	mov	ecx, r8d
	shld	rdx, rax, cl
	mov	rax, rdx
	ret
                                        # -- End function
	.def	 test__shiftright128;
	.scl	2;
	.type	32;
	.endef
	.section	.text,"xr",one_only,test__shiftright128
	.globl	test__shiftright128     # -- Begin function test__shiftright128
	.p2align	4, 0x90
test__shiftright128:                    # @test__shiftright128
# %bb.0:                                # %entry
	mov	rax, rcx
	mov	ecx, r8d
	shrd	rax, rdx, cl
	ret
                                        # -- End function
	.section	.drectve,"yn"
	.ascii	" /DEFAULTLIB:libcmt.lib"
	.ascii	" /DEFAULTLIB:oldnames.lib"

Forgot to add cfe-commits :-( Doing that now.

thakis edited the summary of this revision. (Show Details)Aug 17 2018, 9:58 AM
This revision is now accepted and ready to land.Aug 17 2018, 10:09 AM

r340048, thanks!

rnk accepted this revision.Aug 17 2018, 11:55 AM

lgtm

thakis closed this revision.Aug 20 2018, 10:23 AM