llvm-6502/lib/Transforms/InstCombine
Chris Lattner 62fe406dc2 implement an instcombine xform that canonicalizes casts outside of and-with-constant operations.
This fixes rdar://8808586 which observed that we used to compile:


union xy {
        struct x { _Bool b[15]; } x;
        __attribute__((packed))
        struct y {
                __attribute__((packed)) unsigned long b0to7;
                __attribute__((packed)) unsigned int b8to11;
                __attribute__((packed)) unsigned short b12to13;
                __attribute__((packed)) unsigned char b14;
        } y;
};

struct x
foo(union xy *xy)
{
        return xy->x;
}

into:

_foo:                                   ## @foo
	movq	(%rdi), %rax
	movabsq	$1095216660480, %rcx    ## imm = 0xFF00000000
	andq	%rax, %rcx
	movabsq	$-72057594037927936, %rdx ## imm = 0xFF00000000000000
	andq	%rax, %rdx
	movzbl	%al, %esi
	orq	%rdx, %rsi
	movq	%rax, %rdx
	andq	$65280, %rdx            ## imm = 0xFF00
	orq	%rsi, %rdx
	movq	%rax, %rsi
	andq	$16711680, %rsi         ## imm = 0xFF0000
	orq	%rdx, %rsi
	movl	%eax, %edx
	andl	$-16777216, %edx        ## imm = 0xFFFFFFFFFF000000
	orq	%rsi, %rdx
	orq	%rcx, %rdx
	movabsq	$280375465082880, %rcx  ## imm = 0xFF0000000000
	movq	%rax, %rsi
	andq	%rcx, %rsi
	orq	%rdx, %rsi
	movabsq	$71776119061217280, %r8 ## imm = 0xFF000000000000
	andq	%r8, %rax
	orq	%rsi, %rax
	movzwl	12(%rdi), %edx
	movzbl	14(%rdi), %esi
	shlq	$16, %rsi
	orl	%edx, %esi
	movq	%rsi, %r9
	shlq	$32, %r9
	movl	8(%rdi), %edx
	orq	%r9, %rdx
	andq	%rdx, %rcx
	movzbl	%sil, %esi
	shlq	$32, %rsi
	orq	%rcx, %rsi
	movl	%edx, %ecx
	andl	$-16777216, %ecx        ## imm = 0xFFFFFFFFFF000000
	orq	%rsi, %rcx
	movq	%rdx, %rsi
	andq	$16711680, %rsi         ## imm = 0xFF0000
	orq	%rcx, %rsi
	movq	%rdx, %rcx
	andq	$65280, %rcx            ## imm = 0xFF00
	orq	%rsi, %rcx
	movzbl	%dl, %esi
	orq	%rcx, %rsi
	andq	%r8, %rdx
	orq	%rsi, %rdx
	ret

We now compile this into:

_foo:                                   ## @foo
## BB#0:                                ## %entry
	movzwl	12(%rdi), %eax
	movzbl	14(%rdi), %ecx
	shlq	$16, %rcx
	orl	%eax, %ecx
	shlq	$32, %rcx
	movl	8(%rdi), %edx
	orq	%rcx, %rdx
	movq	(%rdi), %rax
	ret

A small improvement :-)



git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@123520 91177308-0d34-0410-b5e6-96231b3b80d8
2011-01-15 06:32:33 +00:00
..
CMakeLists.txt
InstCombine.h Move getOrEnforceKnownAlignment out of instcombine into Transforms/Utils. 2010-12-25 20:37:57 +00:00
InstCombineAddSub.cpp one more instcombine variant that is needed to work with future changes, 2011-01-15 05:50:18 +00:00
InstCombineAndOrXor.cpp reduce indentation 2011-01-15 05:40:29 +00:00
InstCombineCalls.cpp Teach instcombine about the rest of the SSE and SSE2 conversion 2011-01-10 07:19:37 +00:00
InstCombineCasts.cpp implement an instcombine xform that canonicalizes casts outside of and-with-constant operations. 2011-01-15 06:32:33 +00:00
InstCombineCompares.cpp fix typo 2011-01-15 05:42:47 +00:00
InstCombineLoadStoreAlloca.cpp Move getOrEnforceKnownAlignment out of instcombine into Transforms/Utils. 2010-12-25 20:37:57 +00:00
InstCombineMulDivRem.cpp Add a generic expansion transform: A op (B op' C) -> (A op B) op' (A op C) 2010-12-22 13:36:08 +00:00
InstCombinePHI.cpp
InstCombineSelect.cpp Instcombine: Fix pattern where the sext did not dominate the icmp using it 2011-01-09 16:00:11 +00:00
InstCombineShifts.cpp Move some shift transforms out of instcombine and into InstructionSimplify. 2011-01-14 00:37:45 +00:00
InstCombineSimplifyDemanded.cpp
InstCombineVectorOps.cpp
InstCombineWorklist.h
InstructionCombining.cpp Add a generic expansion transform: A op (B op' C) -> (A op B) op' (A op C) 2010-12-22 13:36:08 +00:00
Makefile