; NOTE: Assertions have been autogenerated by utils/update_llc_test_checks.py ; RUN: llc -mtriple=x86_64-unknown-unknown -mattr=+avx -fixup-byte-word-insts=1 < %s | FileCheck -check-prefix=CHECK -check-prefix=BWON %s ; RUN: llc -mtriple=x86_64-unknown-unknown -mattr=+avx -fixup-byte-word-insts=0 < %s | FileCheck -check-prefix=CHECK -check-prefix=BWOFF %s %struct.A = type { i8, i8, i8, i8, i8, i8, i8, i8 } %struct.B = type { i32, i32, i32, i32, i32, i32, i32, i32 } ; save 1,2,3 ... as one big integer. define void @merge_const_store(i32 %count, %struct.A* nocapture %p) nounwind uwtable noinline ssp { ; CHECK-LABEL: merge_const_store: ; CHECK: # %bb.0: ; CHECK-NEXT: testl %edi, %edi ; CHECK-NEXT: jle .LBB0_3 ; CHECK-NEXT: # %bb.1: # %.lr.ph.preheader ; CHECK-NEXT: movabsq $578437695752307201, %rax # imm = 0x807060504030201 ; CHECK-NEXT: .p2align 4, 0x90 ; CHECK-NEXT: .LBB0_2: # %.lr.ph ; CHECK-NEXT: # =>This Inner Loop Header: Depth=1 ; CHECK-NEXT: movq %rax, (%rsi) ; CHECK-NEXT: addq $8, %rsi ; CHECK-NEXT: decl %edi ; CHECK-NEXT: jne .LBB0_2 ; CHECK-NEXT: .LBB0_3: # %._crit_edge ; CHECK-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{ ; CHECK-LABEL: merge_const_store_no_vec: ; CHECK: # %bb.0: ; CHECK-NEXT: testl %edi, %edi ; CHECK-NEXT: jle .LBB1_2 ; CHECK-NEXT: .p2align 4, 0x90 ; CHECK-NEXT: .LBB1_1: # %.lr.ph ; CHECK-NEXT: # =>This Inner Loop Header: Depth=1 ; CHECK-NEXT: movq $0, (%rsi) ; CHECK-NEXT: movq $0, 8(%rsi) ; CHECK-NEXT: movq $0, 16(%rsi) ; CHECK-NEXT: movq $0, 24(%rsi) ; CHECK-NEXT: addq $32, %rsi ; CHECK-NEXT: decl %edi ; CHECK-NEXT: jne .LBB1_1 ; CHECK-NEXT: .LBB1_2: # %._crit_edge ; CHECK-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 { ; CHECK-LABEL: merge_const_store_vec: ; CHECK: # %bb.0: ; CHECK-NEXT: testl %edi, %edi ; CHECK-NEXT: jle .LBB2_3 ; CHECK-NEXT: # %bb.1: # %.lr.ph.preheader ; CHECK-NEXT: vxorps %xmm0, %xmm0, %xmm0 ; CHECK-NEXT: .p2align 4, 0x90 ; CHECK-NEXT: .LBB2_2: # %.lr.ph ; CHECK-NEXT: # =>This Inner Loop Header: Depth=1 ; CHECK-NEXT: vmovups %ymm0, (%rsi) ; CHECK-NEXT: addq $32, %rsi ; CHECK-NEXT: decl %edi ; CHECK-NEXT: jne .LBB2_2 ; CHECK-NEXT: .LBB2_3: # %._crit_edge ; CHECK-NEXT: vzeroupper ; CHECK-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 { ; CHECK-LABEL: merge_nonconst_store: ; CHECK: # %bb.0: ; CHECK-NEXT: testl %edi, %edi ; CHECK-NEXT: jle .LBB3_2 ; CHECK-NEXT: .p2align 4, 0x90 ; CHECK-NEXT: .LBB3_1: # %.lr.ph ; CHECK-NEXT: # =>This Inner Loop Header: Depth=1 ; CHECK-NEXT: movl $67305985, (%rdx) # imm = 0x4030201 ; CHECK-NEXT: movb %sil, 4(%rdx) ; CHECK-NEXT: movw $1798, 5(%rdx) # imm = 0x706 ; CHECK-NEXT: movb $8, 7(%rdx) ; CHECK-NEXT: addq $8, %rdx ; CHECK-NEXT: decl %edi ; CHECK-NEXT: jne .LBB3_1 ; CHECK-NEXT: .LBB3_2: # %._crit_edge ; CHECK-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 { ; BWON-LABEL: merge_loads_i16: ; BWON: # %bb.0: ; BWON-NEXT: testl %edi, %edi ; BWON-NEXT: jle .LBB4_2 ; BWON-NEXT: .p2align 4, 0x90 ; BWON-NEXT: .LBB4_1: # =>This Inner Loop Header: Depth=1 ; BWON-NEXT: movzwl (%rsi), %eax ; BWON-NEXT: movw %ax, (%rdx) ; BWON-NEXT: addq $8, %rdx ; BWON-NEXT: decl %edi ; BWON-NEXT: jne .LBB4_1 ; BWON-NEXT: .LBB4_2: # %._crit_edge ; BWON-NEXT: retq ; ; BWOFF-LABEL: merge_loads_i16: ; BWOFF: # %bb.0: ; BWOFF-NEXT: testl %edi, %edi ; BWOFF-NEXT: jle .LBB4_2 ; BWOFF-NEXT: .p2align 4, 0x90 ; BWOFF-NEXT: .LBB4_1: # =>This Inner Loop Header: Depth=1 ; BWOFF-NEXT: movw (%rsi), %ax ; BWOFF-NEXT: movw %ax, (%rdx) ; BWOFF-NEXT: addq $8, %rdx ; BWOFF-NEXT: decl %edi ; BWOFF-NEXT: jne .LBB4_1 ; BWOFF-NEXT: .LBB4_2: # %._crit_edge ; 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 ;