1; RUN: opt < %s -basicaa -dse -S | FileCheck %s 2 3define void @write4to7(i32* nocapture %p) { 4; CHECK-LABEL: @write4to7( 5entry: 6 %arrayidx0 = getelementptr inbounds i32, i32* %p, i64 1 7 %p3 = bitcast i32* %arrayidx0 to i8* 8; CHECK: [[GEP:%[0-9]+]] = getelementptr inbounds i8, i8* %p3, i64 4 9; CHECK: call void @llvm.memset.p0i8.i64(i8* [[GEP]], i8 0, i64 24, i32 4, i1 false) 10 call void @llvm.memset.p0i8.i64(i8* %p3, i8 0, i64 28, i32 4, i1 false) 11 %arrayidx1 = getelementptr inbounds i32, i32* %p, i64 1 12 store i32 1, i32* %arrayidx1, align 4 13 ret void 14} 15 16define void @write0to3(i32* nocapture %p) { 17; CHECK-LABEL: @write0to3( 18entry: 19 %p3 = bitcast i32* %p to i8* 20; CHECK: [[GEP:%[0-9]+]] = getelementptr inbounds i8, i8* %p3, i64 4 21; CHECK: call void @llvm.memset.p0i8.i64(i8* [[GEP]], i8 0, i64 24, i32 4, i1 false) 22 call void @llvm.memset.p0i8.i64(i8* %p3, i8 0, i64 28, i32 4, i1 false) 23 store i32 1, i32* %p, align 4 24 ret void 25} 26 27define void @write0to7(i32* nocapture %p) { 28; CHECK-LABEL: @write0to7( 29entry: 30 %p3 = bitcast i32* %p to i8* 31; CHECK: [[GEP:%[0-9]+]] = getelementptr inbounds i8, i8* %p3, i64 8 32; CHECK: call void @llvm.memset.p0i8.i64(i8* [[GEP]], i8 0, i64 24, i32 4, i1 false) 33 call void @llvm.memset.p0i8.i64(i8* %p3, i8 0, i64 32, i32 4, i1 false) 34 %p4 = bitcast i32* %p to i64* 35 store i64 1, i64* %p4, align 8 36 ret void 37} 38 39define void @write0to7_2(i32* nocapture %p) { 40; CHECK-LABEL: @write0to7_2( 41entry: 42 %arrayidx0 = getelementptr inbounds i32, i32* %p, i64 1 43 %p3 = bitcast i32* %arrayidx0 to i8* 44; CHECK: [[GEP:%[0-9]+]] = getelementptr inbounds i8, i8* %p3, i64 4 45; CHECK: call void @llvm.memset.p0i8.i64(i8* [[GEP]], i8 0, i64 24, i32 4, i1 false) 46 call void @llvm.memset.p0i8.i64(i8* %p3, i8 0, i64 28, i32 4, i1 false) 47 %p4 = bitcast i32* %p to i64* 48 store i64 1, i64* %p4, align 8 49 ret void 50} 51 52; We do not trim the beginning of the eariler write if the alignment of the 53; start pointer is changed. 54define void @dontwrite0to3_align8(i32* nocapture %p) { 55; CHECK-LABEL: @dontwrite0to3_align8( 56entry: 57 %p3 = bitcast i32* %p to i8* 58; CHECK: call void @llvm.memset.p0i8.i64(i8* %p3, i8 0, i64 32, i32 8, i1 false) 59 call void @llvm.memset.p0i8.i64(i8* %p3, i8 0, i64 32, i32 8, i1 false) 60 store i32 1, i32* %p, align 4 61 ret void 62} 63 64define void @dontwrite0to1(i32* nocapture %p) { 65; CHECK-LABEL: @dontwrite0to1( 66entry: 67 %p3 = bitcast i32* %p to i8* 68; CHECK: call void @llvm.memset.p0i8.i64(i8* %p3, i8 0, i64 32, i32 4, i1 false) 69 call void @llvm.memset.p0i8.i64(i8* %p3, i8 0, i64 32, i32 4, i1 false) 70 %p4 = bitcast i32* %p to i16* 71 store i16 1, i16* %p4, align 4 72 ret void 73} 74 75define void @dontwrite2to9(i32* nocapture %p) { 76; CHECK-LABEL: @dontwrite2to9( 77entry: 78 %arrayidx0 = getelementptr inbounds i32, i32* %p, i64 1 79 %p3 = bitcast i32* %arrayidx0 to i8* 80; CHECK: call void @llvm.memset.p0i8.i64(i8* %p3, i8 0, i64 32, i32 4, i1 false) 81 call void @llvm.memset.p0i8.i64(i8* %p3, i8 0, i64 32, i32 4, i1 false) 82 %p4 = bitcast i32* %p to i16* 83 %arrayidx2 = getelementptr inbounds i16, i16* %p4, i64 1 84 %p5 = bitcast i16* %arrayidx2 to i64* 85 store i64 1, i64* %p5, align 8 86 ret void 87} 88 89declare void @llvm.memset.p0i8.i64(i8* nocapture, i8, i64, i32, i1) nounwind 90 91