llvm.org GIT mirror llvm / 39acdb0
MemCpyOpt: When forming a memset from stores also take GEP constexprs into account. This is common when storing to global variables. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@163809 91177308-0d34-0410-b5e6-96231b3b80d8 Benjamin Kramer 7 years ago
2 changed file(s) with 27 addition(s) and 3 deletion(s). Raw diff Collapse all Expand all
3737 STATISTIC(NumMoveToCpy, "Number of memmoves converted to memcpy");
3838 STATISTIC(NumCpyToSet, "Number of memcpys converted to memset");
3939
40 static int64_t GetOffsetFromIndex(const GetElementPtrInst *GEP, unsigned Idx,
40 static int64_t GetOffsetFromIndex(const GEPOperator *GEP, unsigned Idx,
4141 bool &VariableIdxFound, const TargetData &TD){
4242 // Skip over the first indices.
4343 gep_type_iterator GTI = gep_type_begin(GEP);
7474 const TargetData &TD) {
7575 Ptr1 = Ptr1->stripPointerCasts();
7676 Ptr2 = Ptr2->stripPointerCasts();
77 GetElementPtrInst *GEP1 = dyn_cast(Ptr1);
78 GetElementPtrInst *GEP2 = dyn_cast(Ptr2);
77 GEPOperator *GEP1 = dyn_cast(Ptr1);
78 GEPOperator *GEP2 = dyn_cast(Ptr2);
7979
8080 bool VariableIdxFound = false;
8181
247247 ; CHECK: @test8
248248 ; CHECK: store <4 x i32> , <4 x i32>* %0, align 16
249249 }
250
251 @test9buf = internal unnamed_addr global [16 x i64] zeroinitializer, align 16
252
253 define void @test9() nounwind {
254 store i8 -1, i8* bitcast ([16 x i64]* @test9buf to i8*), align 16
255 store i8 -1, i8* getelementptr (i8* bitcast ([16 x i64]* @test9buf to i8*), i64 1), align 1
256 store i8 -1, i8* getelementptr (i8* bitcast ([16 x i64]* @test9buf to i8*), i64 2), align 2
257 store i8 -1, i8* getelementptr (i8* bitcast ([16 x i64]* @test9buf to i8*), i64 3), align 1
258 store i8 -1, i8* getelementptr (i8* bitcast ([16 x i64]* @test9buf to i8*), i64 4), align 4
259 store i8 -1, i8* getelementptr (i8* bitcast ([16 x i64]* @test9buf to i8*), i64 5), align 1
260 store i8 -1, i8* getelementptr (i8* bitcast ([16 x i64]* @test9buf to i8*), i64 6), align 2
261 store i8 -1, i8* getelementptr (i8* bitcast ([16 x i64]* @test9buf to i8*), i64 7), align 1
262 store i8 -1, i8* bitcast (i64* getelementptr inbounds ([16 x i64]* @test9buf, i64 0, i64 1) to i8*), align 8
263 store i8 -1, i8* getelementptr (i8* bitcast ([16 x i64]* @test9buf to i8*), i64 9), align 1
264 store i8 -1, i8* getelementptr (i8* bitcast ([16 x i64]* @test9buf to i8*), i64 10), align 2
265 store i8 -1, i8* getelementptr (i8* bitcast ([16 x i64]* @test9buf to i8*), i64 11), align 1
266 store i8 -1, i8* getelementptr (i8* bitcast ([16 x i64]* @test9buf to i8*), i64 12), align 4
267 store i8 -1, i8* getelementptr (i8* bitcast ([16 x i64]* @test9buf to i8*), i64 13), align 1
268 store i8 -1, i8* getelementptr (i8* bitcast ([16 x i64]* @test9buf to i8*), i64 14), align 2
269 store i8 -1, i8* getelementptr (i8* bitcast ([16 x i64]* @test9buf to i8*), i64 15), align 1
270 ret void
271 ; CHECK: @test9(
272 ; CHECK: call void @llvm.memset.p0i8.i64(i8* bitcast ([16 x i64]* @test9buf to i8*), i8 -1, i64 16, i32 16, i1 false)
273 }