1; NOTE: Assertions have been autogenerated by utils/update_test_checks.py 2; RUN: opt -S -mtriple=x86_64-pc_linux -loop-vectorize -instcombine < %s | FileCheck %s --check-prefix=SSE 3; RUN: opt -S -mtriple=x86_64-pc_linux -loop-vectorize -instcombine -mcpu=sandybridge < %s | FileCheck %s --check-prefix=AVX 4; RUN: opt -S -mtriple=x86_64-pc_linux -loop-vectorize -instcombine -mcpu=haswell < %s | FileCheck %s --check-prefix=AVX 5; RUN: opt -S -mtriple=x86_64-pc_linux -loop-vectorize -instcombine -mcpu=slm < %s | FileCheck %s --check-prefix=SSE 6; RUN: opt -S -mtriple=x86_64-pc_linux -loop-vectorize -instcombine -mcpu=atom < %s | FileCheck %s --check-prefix=SSE 7 8define void @foo(i32* noalias nocapture %a, i32* noalias nocapture readonly %b) { 9; SSE-LABEL: @foo( 10; SSE-NEXT: entry: 11; SSE-NEXT: br label [[FOR_BODY:%.*]] 12; SSE: for.cond.cleanup: 13; SSE-NEXT: ret void 14; SSE: for.body: 15; SSE-NEXT: [[INDVARS_IV:%.*]] = phi i64 [ 0, [[ENTRY:%.*]] ], [ [[INDVARS_IV_NEXT:%.*]], [[FOR_BODY]] ] 16; SSE-NEXT: [[TMP0:%.*]] = shl nuw nsw i64 [[INDVARS_IV]], 1 17; SSE-NEXT: [[ARRAYIDX:%.*]] = getelementptr inbounds i32, i32* [[B:%.*]], i64 [[TMP0]] 18; SSE-NEXT: [[TMP1:%.*]] = load i32, i32* [[ARRAYIDX]], align 4 19; SSE-NEXT: [[TMP2:%.*]] = or i64 [[TMP0]], 1 20; SSE-NEXT: [[ARRAYIDX3:%.*]] = getelementptr inbounds i32, i32* [[B]], i64 [[TMP2]] 21; SSE-NEXT: [[TMP3:%.*]] = load i32, i32* [[ARRAYIDX3]], align 4 22; SSE-NEXT: [[ADD4:%.*]] = add nsw i32 [[TMP3]], [[TMP1]] 23; SSE-NEXT: [[ARRAYIDX6:%.*]] = getelementptr inbounds i32, i32* [[A:%.*]], i64 [[INDVARS_IV]] 24; SSE-NEXT: store i32 [[ADD4]], i32* [[ARRAYIDX6]], align 4 25; SSE-NEXT: [[INDVARS_IV_NEXT]] = add nuw nsw i64 [[INDVARS_IV]], 1 26; SSE-NEXT: [[EXITCOND:%.*]] = icmp eq i64 [[INDVARS_IV_NEXT]], 1024 27; SSE-NEXT: br i1 [[EXITCOND]], label [[FOR_COND_CLEANUP:%.*]], label [[FOR_BODY]] 28; 29; AVX-LABEL: @foo( 30; AVX-NEXT: entry: 31; AVX-NEXT: br i1 false, label [[SCALAR_PH:%.*]], label [[VECTOR_PH:%.*]] 32; AVX: vector.ph: 33; AVX-NEXT: br label [[VECTOR_BODY:%.*]] 34; AVX: vector.body: 35; AVX-NEXT: [[INDEX:%.*]] = phi i64 [ 0, [[VECTOR_PH]] ], [ [[INDEX_NEXT:%.*]], [[VECTOR_BODY]] ] 36; AVX-NEXT: [[TMP0:%.*]] = shl nsw i64 [[INDEX]], 1 37; AVX-NEXT: [[TMP1:%.*]] = getelementptr inbounds i32, i32* [[B:%.*]], i64 [[TMP0]] 38; AVX-NEXT: [[TMP2:%.*]] = bitcast i32* [[TMP1]] to <8 x i32>* 39; AVX-NEXT: [[WIDE_VEC:%.*]] = load <8 x i32>, <8 x i32>* [[TMP2]], align 4 40; AVX-NEXT: [[STRIDED_VEC:%.*]] = shufflevector <8 x i32> [[WIDE_VEC]], <8 x i32> undef, <4 x i32> <i32 0, i32 2, i32 4, i32 6> 41; AVX-NEXT: [[STRIDED_VEC1:%.*]] = shufflevector <8 x i32> [[WIDE_VEC]], <8 x i32> undef, <4 x i32> <i32 1, i32 3, i32 5, i32 7> 42; AVX-NEXT: [[TMP3:%.*]] = add nsw <4 x i32> [[STRIDED_VEC1]], [[STRIDED_VEC]] 43; AVX-NEXT: [[TMP4:%.*]] = getelementptr inbounds i32, i32* [[A:%.*]], i64 [[INDEX]] 44; AVX-NEXT: [[TMP5:%.*]] = bitcast i32* [[TMP4]] to <4 x i32>* 45; AVX-NEXT: store <4 x i32> [[TMP3]], <4 x i32>* [[TMP5]], align 4 46; AVX-NEXT: [[INDEX_NEXT]] = add i64 [[INDEX]], 4 47; AVX-NEXT: [[TMP6:%.*]] = icmp eq i64 [[INDEX_NEXT]], 1024 48; AVX-NEXT: br i1 [[TMP6]], label [[MIDDLE_BLOCK:%.*]], label [[VECTOR_BODY]], [[LOOP0:!llvm.loop !.*]] 49; AVX: middle.block: 50; AVX-NEXT: br i1 true, label [[FOR_COND_CLEANUP:%.*]], label [[SCALAR_PH]] 51; AVX: scalar.ph: 52; AVX-NEXT: br label [[FOR_BODY:%.*]] 53; AVX: for.cond.cleanup: 54; AVX-NEXT: ret void 55; AVX: for.body: 56; AVX-NEXT: br i1 undef, label [[FOR_COND_CLEANUP]], label [[FOR_BODY]], [[LOOP2:!llvm.loop !.*]] 57; 58entry: 59 br label %for.body 60 61for.cond.cleanup: ; preds = %for.body 62 ret void 63 64for.body: ; preds = %for.body, %entry 65 %indvars.iv = phi i64 [ 0, %entry ], [ %indvars.iv.next, %for.body ] 66 %0 = shl nsw i64 %indvars.iv, 1 67 %arrayidx = getelementptr inbounds i32, i32* %b, i64 %0 68 %1 = load i32, i32* %arrayidx, align 4 69 %2 = or i64 %0, 1 70 %arrayidx3 = getelementptr inbounds i32, i32* %b, i64 %2 71 %3 = load i32, i32* %arrayidx3, align 4 72 %add4 = add nsw i32 %3, %1 73 %arrayidx6 = getelementptr inbounds i32, i32* %a, i64 %indvars.iv 74 store i32 %add4, i32* %arrayidx6, align 4 75 %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1 76 %exitcond = icmp eq i64 %indvars.iv.next, 1024 77 br i1 %exitcond, label %for.cond.cleanup, label %for.body 78} 79