vitalybuka created this revision. vitalybuka added reviewers: eugenis, pcc, jfb. Herald added subscribers: cfe-commits, dexonsmith. Herald added a project: clang.
In some cases llvm::getMostFrequentByte can't analyze a constant so we write zeros and then override the rest with stores. These zeros are not needed and we can keep only stores. Repository: rG LLVM Github Monorepo https://reviews.llvm.org/D64387 Files: clang/lib/CodeGen/CGDecl.cpp clang/test/CodeGen/init-memset.c Index: clang/test/CodeGen/init-memset.c =================================================================== --- clang/test/CodeGen/init-memset.c +++ clang/test/CodeGen/init-memset.c @@ -49,7 +49,7 @@ void test_pointers() { // CHECK-LABEL: define void @test_pointers() void *a[] = {&use, &use, &use, &use, &use, &use}; - // CHECK: call void @llvm.memset.{{.*}} + // CHECK-NOT: @llvm.memset. // CHECK: store i8* // CHECK: store i8* // CHECK: store i8* Index: clang/lib/CodeGen/CGDecl.cpp =================================================================== --- clang/lib/CodeGen/CGDecl.cpp +++ clang/lib/CodeGen/CGDecl.cpp @@ -973,15 +973,10 @@ if (GlobalSize <= SizeLimit) return nullptr; - if (!MFB.Value) { - // We don't know most frequent byte, we may still completely initialize it - // with small number of stores. - // TODO: Use llvm::UndefValue::get. If we get here and later we decide - // that number of stores is small enough to use memset+store then store are - // going to replace entire bzeroed range. With UndefValue we can skip that - // bogus memset. I will do that as a separate patch. - MFB.Value = llvm::ConstantInt::get(CGM.Int8Ty, 0); - } + // We don't know most frequent byte, we may still completely initialize it + // with small number of stores. + if (!MFB.Value) + MFB.Value = llvm::UndefValue::get(CGM.Int8Ty); unsigned StoreBudget = 6; return canEmitStoresForInitAfterMemset(CGM, Init, MFB.Value, StoreBudget)
Index: clang/test/CodeGen/init-memset.c =================================================================== --- clang/test/CodeGen/init-memset.c +++ clang/test/CodeGen/init-memset.c @@ -49,7 +49,7 @@ void test_pointers() { // CHECK-LABEL: define void @test_pointers() void *a[] = {&use, &use, &use, &use, &use, &use}; - // CHECK: call void @llvm.memset.{{.*}} + // CHECK-NOT: @llvm.memset. // CHECK: store i8* // CHECK: store i8* // CHECK: store i8* Index: clang/lib/CodeGen/CGDecl.cpp =================================================================== --- clang/lib/CodeGen/CGDecl.cpp +++ clang/lib/CodeGen/CGDecl.cpp @@ -973,15 +973,10 @@ if (GlobalSize <= SizeLimit) return nullptr; - if (!MFB.Value) { - // We don't know most frequent byte, we may still completely initialize it - // with small number of stores. - // TODO: Use llvm::UndefValue::get. If we get here and later we decide - // that number of stores is small enough to use memset+store then store are - // going to replace entire bzeroed range. With UndefValue we can skip that - // bogus memset. I will do that as a separate patch. - MFB.Value = llvm::ConstantInt::get(CGM.Int8Ty, 0); - } + // We don't know most frequent byte, we may still completely initialize it + // with small number of stores. + if (!MFB.Value) + MFB.Value = llvm::UndefValue::get(CGM.Int8Ty); unsigned StoreBudget = 6; return canEmitStoresForInitAfterMemset(CGM, Init, MFB.Value, StoreBudget)
_______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits