; NOTE: Assertions have been autogenerated by utils/update_llc_test_checks.py ; RUN: llc -mtriple=i686-unknown-unknown -mattr=+avx -fixup-byte-word-insts=1 < %s | FileCheck -check-prefixes=X86,X86-BWON %s ; RUN: llc -mtriple=i686-unknown-unknown -mattr=+avx -fixup-byte-word-insts=0 < %s | FileCheck -check-prefixes=X86,X86-BWOFF %s ; RUN: llc -mtriple=x86_64-unknown-unknown -mattr=+avx -fixup-byte-word-insts=1 < %s | FileCheck -check-prefixes=X64,X64-BWON %s ; RUN: llc -mtriple=x86_64-unknown-unknown -mattr=+avx -fixup-byte-word-insts=0 < %s | FileCheck -check-prefixes=X64,X64-BWOFF %s %struct.A = type { i8, i8, i8, i8, i8, i8, i8, i8 } %struct.B = type { i32, i32, i32, i32, i32, i32, i32, i32 } %struct.C = type { i8, i8, i8, i8, i32, i32, i32, i64 } ; save 1,2,3 ... as one big integer. define void @merge_const_store(i32 %count, %struct.A* nocapture %p) nounwind uwtable noinline ssp { ; X86-LABEL: merge_const_store: ; X86: # %bb.0: ; X86-NEXT: movl {{[0-9]+}}(%esp), %eax ; X86-NEXT: testl %eax, %eax ; X86-NEXT: jle .LBB0_3 ; X86-NEXT: # %bb.1: # %.lr.ph.preheader ; X86-NEXT: movl {{[0-9]+}}(%esp), %ecx ; X86-NEXT: .p2align 4, 0x90 ; X86-NEXT: .LBB0_2: # %.lr.ph ; X86-NEXT: # =>This Inner Loop Header: Depth=1 ; X86-NEXT: movl $67305985, (%ecx) # imm = 0x4030201 ; X86-NEXT: movl $134678021, 4(%ecx) # imm = 0x8070605 ; X86-NEXT: addl $8, %ecx ; X86-NEXT: decl %eax ; X86-NEXT: jne .LBB0_2 ; X86-NEXT: .LBB0_3: # %._crit_edge ; X86-NEXT: retl ; ; X64-LABEL: merge_const_store: ; X64: # %bb.0: ; X64-NEXT: testl %edi, %edi ; X64-NEXT: jle .LBB0_3 ; X64-NEXT: # %bb.1: # %.lr.ph.preheader ; X64-NEXT: movabsq $578437695752307201, %rax # imm = 0x807060504030201 ; X64-NEXT: .p2align 4, 0x90 ; X64-NEXT: .LBB0_2: # %.lr.ph ; X64-NEXT: # =>This Inner Loop Header: Depth=1 ; X64-NEXT: movq %rax, (%rsi) ; X64-NEXT: addq $8, %rsi ; X64-NEXT: decl %edi ; X64-NEXT: jne .LBB0_2 ; X64-NEXT: .LBB0_3: # %._crit_edge ; X64-NEXT: retq %1 = icmp sgt i32 %count, 0 br i1 %1, label %.lr.ph, label %._crit_edge .lr.ph: %i.02 = phi i32 [ %10, %.lr.ph ], [ 0, %0 ] %.01 = phi %struct.A* [ %11, %.lr.ph ], [ %p, %0 ] %2 = getelementptr inbounds %struct.A, %struct.A* %.01, i64 0, i32 0 store i8 1, i8* %2, align 1 %3 = getelementptr inbounds %struct.A, %struct.A* %.01, i64 0, i32 1 store i8 2, i8* %3, align 1 %4 = getelementptr inbounds %struct.A, %struct.A* %.01, i64 0, i32 2 store i8 3, i8* %4, align 1 %5 = getelementptr inbounds %struct.A, %struct.A* %.01, i64 0, i32 3 store i8 4, i8* %5, align 1 %6 = getelementptr inbounds %struct.A, %struct.A* %.01, i64 0, i32 4 store i8 5, i8* %6, align 1 %7 = getelementptr inbounds %struct.A, %struct.A* %.01, i64 0, i32 5 store i8 6, i8* %7, align 1 %8 = getelementptr inbounds %struct.A, %struct.A* %.01, i64 0, i32 6 store i8 7, i8* %8, align 1 %9 = getelementptr inbounds %struct.A, %struct.A* %.01, i64 0, i32 7 store i8 8, i8* %9, align 1 %10 = add nsw i32 %i.02, 1 %11 = getelementptr inbounds %struct.A, %struct.A* %.01, i64 1 %exitcond = icmp eq i32 %10, %count br i1 %exitcond, label %._crit_edge, label %.lr.ph ._crit_edge: ret void } ; No vectors because we use noimplicitfloat define void @merge_const_store_no_vec(i32 %count, %struct.B* nocapture %p) noimplicitfloat{ ; X86-LABEL: merge_const_store_no_vec: ; X86: # %bb.0: ; X86-NEXT: movl {{[0-9]+}}(%esp), %eax ; X86-NEXT: testl %eax, %eax ; X86-NEXT: jle .LBB1_3 ; X86-NEXT: # %bb.1: # %.lr.ph.preheader ; X86-NEXT: movl {{[0-9]+}}(%esp), %ecx ; X86-NEXT: .p2align 4, 0x90 ; X86-NEXT: .LBB1_2: # %.lr.ph ; X86-NEXT: # =>This Inner Loop Header: Depth=1 ; X86-NEXT: movl $0, (%ecx) ; X86-NEXT: movl $0, 4(%ecx) ; X86-NEXT: movl $0, 8(%ecx) ; X86-NEXT: movl $0, 12(%ecx) ; X86-NEXT: movl $0, 16(%ecx) ; X86-NEXT: movl $0, 20(%ecx) ; X86-NEXT: movl $0, 24(%ecx) ; X86-NEXT: movl $0, 28(%ecx) ; X86-NEXT: addl $32, %ecx ; X86-NEXT: decl %eax ; X86-NEXT: jne .LBB1_2 ; X86-NEXT: .LBB1_3: # %._crit_edge ; X86-NEXT: retl ; ; X64-LABEL: merge_const_store_no_vec: ; X64: # %bb.0: ; X64-NEXT: testl %edi, %edi ; X64-NEXT: jle .LBB1_2 ; X64-NEXT: .p2align 4, 0x90 ; X64-NEXT: .LBB1_1: # %.lr.ph ; X64-NEXT: # =>This Inner Loop Header: Depth=1 ; X64-NEXT: movq $0, (%rsi) ; X64-NEXT: movq $0, 8(%rsi) ; X64-NEXT: movq $0, 16(%rsi) ; X64-NEXT: movq $0, 24(%rsi) ; X64-NEXT: addq $32, %rsi ; X64-NEXT: decl %edi ; X64-NEXT: jne .LBB1_1 ; X64-NEXT: .LBB1_2: # %._crit_edge ; X64-NEXT: retq %1 = icmp sgt i32 %count, 0 br i1 %1, label %.lr.ph, label %._crit_edge .lr.ph: %i.02 = phi i32 [ %10, %.lr.ph ], [ 0, %0 ] %.01 = phi %struct.B* [ %11, %.lr.ph ], [ %p, %0 ] %2 = getelementptr inbounds %struct.B, %struct.B* %.01, i64 0, i32 0 store i32 0, i32* %2, align 4 %3 = getelementptr inbounds %struct.B, %struct.B* %.01, i64 0, i32 1 store i32 0, i32* %3, align 4 %4 = getelementptr inbounds %struct.B, %struct.B* %.01, i64 0, i32 2 store i32 0, i32* %4, align 4 %5 = getelementptr inbounds %struct.B, %struct.B* %.01, i64 0, i32 3 store i32 0, i32* %5, align 4 %6 = getelementptr inbounds %struct.B, %struct.B* %.01, i64 0, i32 4 store i32 0, i32* %6, align 4 %7 = getelementptr inbounds %struct.B, %struct.B* %.01, i64 0, i32 5 store i32 0, i32* %7, align 4 %8 = getelementptr inbounds %struct.B, %struct.B* %.01, i64 0, i32 6 store i32 0, i32* %8, align 4 %9 = getelementptr inbounds %struct.B, %struct.B* %.01, i64 0, i32 7 store i32 0, i32* %9, align 4 %10 = add nsw i32 %i.02, 1 %11 = getelementptr inbounds %struct.B, %struct.B* %.01, i64 1 %exitcond = icmp eq i32 %10, %count br i1 %exitcond, label %._crit_edge, label %.lr.ph ._crit_edge: ret void } ; Move the constants using a single vector store. define void @merge_const_store_vec(i32 %count, %struct.B* nocapture %p) nounwind uwtable noinline ssp { ; X86-LABEL: merge_const_store_vec: ; X86: # %bb.0: ; X86-NEXT: movl {{[0-9]+}}(%esp), %eax ; X86-NEXT: testl %eax, %eax ; X86-NEXT: jle .LBB2_3 ; X86-NEXT: # %bb.1: # %.lr.ph.preheader ; X86-NEXT: movl {{[0-9]+}}(%esp), %ecx ; X86-NEXT: vxorps %xmm0, %xmm0, %xmm0 ; X86-NEXT: .p2align 4, 0x90 ; X86-NEXT: .LBB2_2: # %.lr.ph ; X86-NEXT: # =>This Inner Loop Header: Depth=1 ; X86-NEXT: vmovups %ymm0, (%ecx) ; X86-NEXT: addl $32, %ecx ; X86-NEXT: decl %eax ; X86-NEXT: jne .LBB2_2 ; X86-NEXT: .LBB2_3: # %._crit_edge ; X86-NEXT: vzeroupper ; X86-NEXT: retl ; ; X64-LABEL: merge_const_store_vec: ; X64: # %bb.0: ; X64-NEXT: testl %edi, %edi ; X64-NEXT: jle .LBB2_3 ; X64-NEXT: # %bb.1: # %.lr.ph.preheader ; X64-NEXT: vxorps %xmm0, %xmm0, %xmm0 ; X64-NEXT: .p2align 4, 0x90 ; X64-NEXT: .LBB2_2: # %.lr.ph ; X64-NEXT: # =>This Inner Loop Header: Depth=1 ; X64-NEXT: vmovups %ymm0, (%rsi) ; X64-NEXT: addq $32, %rsi ; X64-NEXT: decl %edi ; X64-NEXT: jne .LBB2_2 ; X64-NEXT: .LBB2_3: # %._crit_edge ; X64-NEXT: vzeroupper ; X64-NEXT: retq %1 = icmp sgt i32 %count, 0 br i1 %1, label %.lr.ph, label %._crit_edge .lr.ph: %i.02 = phi i32 [ %10, %.lr.ph ], [ 0, %0 ] %.01 = phi %struct.B* [ %11, %.lr.ph ], [ %p, %0 ] %2 = getelementptr inbounds %struct.B, %struct.B* %.01, i64 0, i32 0 store i32 0, i32* %2, align 4 %3 = getelementptr inbounds %struct.B, %struct.B* %.01, i64 0, i32 1 store i32 0, i32* %3, align 4 %4 = getelementptr inbounds %struct.B, %struct.B* %.01, i64 0, i32 2 store i32 0, i32* %4, align 4 %5 = getelementptr inbounds %struct.B, %struct.B* %.01, i64 0, i32 3 store i32 0, i32* %5, align 4 %6 = getelementptr inbounds %struct.B, %struct.B* %.01, i64 0, i32 4 store i32 0, i32* %6, align 4 %7 = getelementptr inbounds %struct.B, %struct.B* %.01, i64 0, i32 5 store i32 0, i32* %7, align 4 %8 = getelementptr inbounds %struct.B, %struct.B* %.01, i64 0, i32 6 store i32 0, i32* %8, align 4 %9 = getelementptr inbounds %struct.B, %struct.B* %.01, i64 0, i32 7 store i32 0, i32* %9, align 4 %10 = add nsw i32 %i.02, 1 %11 = getelementptr inbounds %struct.B, %struct.B* %.01, i64 1 %exitcond = icmp eq i32 %10, %count br i1 %exitcond, label %._crit_edge, label %.lr.ph ._crit_edge: ret void } ; Move the first 4 constants as a single vector. Move the rest as scalars. define void @merge_nonconst_store(i32 %count, i8 %zz, %struct.A* nocapture %p) nounwind uwtable noinline ssp { ; X86-BWON-LABEL: merge_nonconst_store: ; X86-BWON: # %bb.0: ; X86-BWON-NEXT: movl {{[0-9]+}}(%esp), %eax ; X86-BWON-NEXT: testl %eax, %eax ; X86-BWON-NEXT: jle .LBB3_3 ; X86-BWON-NEXT: # %bb.1: # %.lr.ph.preheader ; X86-BWON-NEXT: movl {{[0-9]+}}(%esp), %ecx ; X86-BWON-NEXT: movzbl {{[0-9]+}}(%esp), %edx ; X86-BWON-NEXT: .p2align 4, 0x90 ; X86-BWON-NEXT: .LBB3_2: # %.lr.ph ; X86-BWON-NEXT: # =>This Inner Loop Header: Depth=1 ; X86-BWON-NEXT: movl $67305985, (%ecx) # imm = 0x4030201 ; X86-BWON-NEXT: movb %dl, 4(%ecx) ; X86-BWON-NEXT: movw $1798, 5(%ecx) # imm = 0x706 ; X86-BWON-NEXT: movb $8, 7(%ecx) ; X86-BWON-NEXT: addl $8, %ecx ; X86-BWON-NEXT: decl %eax ; X86-BWON-NEXT: jne .LBB3_2 ; X86-BWON-NEXT: .LBB3_3: # %._crit_edge ; X86-BWON-NEXT: retl ; ; X86-BWOFF-LABEL: merge_nonconst_store: ; X86-BWOFF: # %bb.0: ; X86-BWOFF-NEXT: movl {{[0-9]+}}(%esp), %eax ; X86-BWOFF-NEXT: testl %eax, %eax ; X86-BWOFF-NEXT: jle .LBB3_3 ; X86-BWOFF-NEXT: # %bb.1: # %.lr.ph.preheader ; X86-BWOFF-NEXT: movl {{[0-9]+}}(%esp), %ecx ; X86-BWOFF-NEXT: movb {{[0-9]+}}(%esp), %dl ; X86-BWOFF-NEXT: .p2align 4, 0x90 ; X86-BWOFF-NEXT: .LBB3_2: # %.lr.ph ; X86-BWOFF-NEXT: # =>This Inner Loop Header: Depth=1 ; X86-BWOFF-NEXT: movl $67305985, (%ecx) # imm = 0x4030201 ; X86-BWOFF-NEXT: movb %dl, 4(%ecx) ; X86-BWOFF-NEXT: movw $1798, 5(%ecx) # imm = 0x706 ; X86-BWOFF-NEXT: movb $8, 7(%ecx) ; X86-BWOFF-NEXT: addl $8, %ecx ; X86-BWOFF-NEXT: decl %eax ; X86-BWOFF-NEXT: jne .LBB3_2 ; X86-BWOFF-NEXT: .LBB3_3: # %._crit_edge ; X86-BWOFF-NEXT: retl ; ; X64-LABEL: merge_nonconst_store: ; X64: # %bb.0: ; X64-NEXT: testl %edi, %edi ; X64-NEXT: jle .LBB3_2 ; X64-NEXT: .p2align 4, 0x90 ; X64-NEXT: .LBB3_1: # %.lr.ph ; X64-NEXT: # =>This Inner Loop Header: Depth=1 ; X64-NEXT: movl $67305985, (%rdx) # imm = 0x4030201 ; X64-NEXT: movb %sil, 4(%rdx) ; X64-NEXT: movw $1798, 5(%rdx) # imm = 0x706 ; X64-NEXT: movb $8, 7(%rdx) ; X64-NEXT: addq $8, %rdx ; X64-NEXT: decl %edi ; X64-NEXT: jne .LBB3_1 ; X64-NEXT: .LBB3_2: # %._crit_edge ; X64-NEXT: retq %1 = icmp sgt i32 %count, 0 br i1 %1, label %.lr.ph, label %._crit_edge .lr.ph: %i.02 = phi i32 [ %10, %.lr.ph ], [ 0, %0 ] %.01 = phi %struct.A* [ %11, %.lr.ph ], [ %p, %0 ] %2 = getelementptr inbounds %struct.A, %struct.A* %.01, i64 0, i32 0 store i8 1, i8* %2, align 1 %3 = getelementptr inbounds %struct.A, %struct.A* %.01, i64 0, i32 1 store i8 2, i8* %3, align 1 %4 = getelementptr inbounds %struct.A, %struct.A* %.01, i64 0, i32 2 store i8 3, i8* %4, align 1 %5 = getelementptr inbounds %struct.A, %struct.A* %.01, i64 0, i32 3 store i8 4, i8* %5, align 1 %6 = getelementptr inbounds %struct.A, %struct.A* %.01, i64 0, i32 4 store i8 %zz, i8* %6, align 1 ; <----------- Not a const; %7 = getelementptr inbounds %struct.A, %struct.A* %.01, i64 0, i32 5 store i8 6, i8* %7, align 1 %8 = getelementptr inbounds %struct.A, %struct.A* %.01, i64 0, i32 6 store i8 7, i8* %8, align 1 %9 = getelementptr inbounds %struct.A, %struct.A* %.01, i64 0, i32 7 store i8 8, i8* %9, align 1 %10 = add nsw i32 %i.02, 1 %11 = getelementptr inbounds %struct.A, %struct.A* %.01, i64 1 %exitcond = icmp eq i32 %10, %count br i1 %exitcond, label %._crit_edge, label %.lr.ph ._crit_edge: ret void } define void @merge_loads_i16(i32 %count, %struct.A* noalias nocapture %q, %struct.A* noalias nocapture %p) nounwind uwtable noinline ssp { ; X86-BWON-LABEL: merge_loads_i16: ; X86-BWON: # %bb.0: ; X86-BWON-NEXT: pushl %esi ; X86-BWON-NEXT: .cfi_def_cfa_offset 8 ; X86-BWON-NEXT: .cfi_offset %esi, -8 ; X86-BWON-NEXT: movl {{[0-9]+}}(%esp), %eax ; X86-BWON-NEXT: testl %eax, %eax ; X86-BWON-NEXT: jle .LBB4_3 ; X86-BWON-NEXT: # %bb.1: # %.lr.ph ; X86-BWON-NEXT: movl {{[0-9]+}}(%esp), %ecx ; X86-BWON-NEXT: movl {{[0-9]+}}(%esp), %edx ; X86-BWON-NEXT: .p2align 4, 0x90 ; X86-BWON-NEXT: .LBB4_2: # =>This Inner Loop Header: Depth=1 ; X86-BWON-NEXT: movzwl (%edx), %esi ; X86-BWON-NEXT: movw %si, (%ecx) ; X86-BWON-NEXT: addl $8, %ecx ; X86-BWON-NEXT: decl %eax ; X86-BWON-NEXT: jne .LBB4_2 ; X86-BWON-NEXT: .LBB4_3: # %._crit_edge ; X86-BWON-NEXT: popl %esi ; X86-BWON-NEXT: .cfi_def_cfa_offset 4 ; X86-BWON-NEXT: retl ; ; X86-BWOFF-LABEL: merge_loads_i16: ; X86-BWOFF: # %bb.0: ; X86-BWOFF-NEXT: pushl %esi ; X86-BWOFF-NEXT: .cfi_def_cfa_offset 8 ; X86-BWOFF-NEXT: .cfi_offset %esi, -8 ; X86-BWOFF-NEXT: movl {{[0-9]+}}(%esp), %eax ; X86-BWOFF-NEXT: testl %eax, %eax ; X86-BWOFF-NEXT: jle .LBB4_3 ; X86-BWOFF-NEXT: # %bb.1: # %.lr.ph ; X86-BWOFF-NEXT: movl {{[0-9]+}}(%esp), %ecx ; X86-BWOFF-NEXT: movl {{[0-9]+}}(%esp), %edx ; X86-BWOFF-NEXT: .p2align 4, 0x90 ; X86-BWOFF-NEXT: .LBB4_2: # =>This Inner Loop Header: Depth=1 ; X86-BWOFF-NEXT: movw (%edx), %si ; X86-BWOFF-NEXT: movw %si, (%ecx) ; X86-BWOFF-NEXT: addl $8, %ecx ; X86-BWOFF-NEXT: decl %eax ; X86-BWOFF-NEXT: jne .LBB4_2 ; X86-BWOFF-NEXT: .LBB4_3: # %._crit_edge ; X86-BWOFF-NEXT: popl %esi ; X86-BWOFF-NEXT: .cfi_def_cfa_offset 4 ; X86-BWOFF-NEXT: retl ; ; X64-BWON-LABEL: merge_loads_i16: ; X64-BWON: # %bb.0: ; X64-BWON-NEXT: testl %edi, %edi ; X64-BWON-NEXT: jle .LBB4_2 ; X64-BWON-NEXT: .p2align 4, 0x90 ; X64-BWON-NEXT: .LBB4_1: # =>This Inner Loop Header: Depth=1 ; X64-BWON-NEXT: movzwl (%rsi), %eax ; X64-BWON-NEXT: movw %ax, (%rdx) ; X64-BWON-NEXT: addq $8, %rdx ; X64-BWON-NEXT: decl %edi ; X64-BWON-NEXT: jne .LBB4_1 ; X64-BWON-NEXT: .LBB4_2: # %._crit_edge ; X64-BWON-NEXT: retq ; ; X64-BWOFF-LABEL: merge_loads_i16: ; X64-BWOFF: # %bb.0: ; X64-BWOFF-NEXT: testl %edi, %edi ; X64-BWOFF-NEXT: jle .LBB4_2 ; X64-BWOFF-NEXT: .p2align 4, 0x90 ; X64-BWOFF-NEXT: .LBB4_1: # =>This Inner Loop Header: Depth=1 ; X64-BWOFF-NEXT: movw (%rsi), %ax ; X64-BWOFF-NEXT: movw %ax, (%rdx) ; X64-BWOFF-NEXT: addq $8, %rdx ; X64-BWOFF-NEXT: decl %edi ; X64-BWOFF-NEXT: jne .LBB4_1 ; X64-BWOFF-NEXT: .LBB4_2: # %._crit_edge ; X64-BWOFF-NEXT: retq %1 = icmp sgt i32 %count, 0 br i1 %1, label %.lr.ph, label %._crit_edge .lr.ph: ; preds = %0 %2 = getelementptr inbounds %struct.A, %struct.A* %q, i64 0, i32 0 %3 = getelementptr inbounds %struct.A, %struct.A* %q, i64 0, i32 1 br label %4 ;