jgalenson created this revision. jgalenson added reviewers: eugenis, chandlerc. Herald added a subscriber: cfe-commits.
Running the bounds checking sanitizer earlier makes it easier for other optimizations to remove the checks it inserts. While it could also inhibit other optimizations, I ran a few benchmarks and this did seem to improve performance and code size slightly. Note that I'm not sure how to hook this up to the new PM, as I couldn't find a similar hook into the beginning of the pipeline. Are there any suggestions on what to do about that, or is it fine for this to work just on the old PM? Repository: rC Clang https://reviews.llvm.org/D49492 Files: lib/CodeGen/BackendUtil.cpp test/CodeGen/bounds-checking-opt.c Index: test/CodeGen/bounds-checking-opt.c =================================================================== --- /dev/null +++ test/CodeGen/bounds-checking-opt.c @@ -0,0 +1,20 @@ +// RUN: %clang -S -fsanitize=local-bounds -emit-llvm -target x86_64-- %s -o - | FileCheck -check-prefix=O0 %s +// RUN: %clang -S -fsanitize=local-bounds -emit-llvm -target x86_64-- -O2 %s -o - | FileCheck -check-prefix=O2 %s +// RUN: %clang -S -fsanitize=local-bounds -emit-llvm -target aarch64-- %s -o - | FileCheck -check-prefix=O0 %s +// RUN: %clang -S -fsanitize=local-bounds -emit-llvm -target aarch64-- -O2 %s -o - | FileCheck -check-prefix=O2 %s + +extern void fill(int *arr); + +// CHECK-LABEL: @f +int f(int x) { + // O0: call {{.*}} @llvm.trap + // O2-NOT: call {{.*}} @llvm.trap + int foo[1000]; + fill(foo); + int sum = 0; + #pragma clang loop vectorize(disable) + #pragma clang loop unroll(disable) + for (unsigned i = 0; i < 1000; i++) + sum += foo[i]; + return sum; +} Index: lib/CodeGen/BackendUtil.cpp =================================================================== --- lib/CodeGen/BackendUtil.cpp +++ lib/CodeGen/BackendUtil.cpp @@ -562,7 +562,7 @@ addCoroutinePassesToExtensionPoints(PMBuilder); if (LangOpts.Sanitize.has(SanitizerKind::LocalBounds)) { - PMBuilder.addExtension(PassManagerBuilder::EP_ScalarOptimizerLate, + PMBuilder.addExtension(PassManagerBuilder::EP_EarlyAsPossible, addBoundsCheckingPass); PMBuilder.addExtension(PassManagerBuilder::EP_EnabledOnOptLevel0, addBoundsCheckingPass);
Index: test/CodeGen/bounds-checking-opt.c =================================================================== --- /dev/null +++ test/CodeGen/bounds-checking-opt.c @@ -0,0 +1,20 @@ +// RUN: %clang -S -fsanitize=local-bounds -emit-llvm -target x86_64-- %s -o - | FileCheck -check-prefix=O0 %s +// RUN: %clang -S -fsanitize=local-bounds -emit-llvm -target x86_64-- -O2 %s -o - | FileCheck -check-prefix=O2 %s +// RUN: %clang -S -fsanitize=local-bounds -emit-llvm -target aarch64-- %s -o - | FileCheck -check-prefix=O0 %s +// RUN: %clang -S -fsanitize=local-bounds -emit-llvm -target aarch64-- -O2 %s -o - | FileCheck -check-prefix=O2 %s + +extern void fill(int *arr); + +// CHECK-LABEL: @f +int f(int x) { + // O0: call {{.*}} @llvm.trap + // O2-NOT: call {{.*}} @llvm.trap + int foo[1000]; + fill(foo); + int sum = 0; + #pragma clang loop vectorize(disable) + #pragma clang loop unroll(disable) + for (unsigned i = 0; i < 1000; i++) + sum += foo[i]; + return sum; +} Index: lib/CodeGen/BackendUtil.cpp =================================================================== --- lib/CodeGen/BackendUtil.cpp +++ lib/CodeGen/BackendUtil.cpp @@ -562,7 +562,7 @@ addCoroutinePassesToExtensionPoints(PMBuilder); if (LangOpts.Sanitize.has(SanitizerKind::LocalBounds)) { - PMBuilder.addExtension(PassManagerBuilder::EP_ScalarOptimizerLate, + PMBuilder.addExtension(PassManagerBuilder::EP_EarlyAsPossible, addBoundsCheckingPass); PMBuilder.addExtension(PassManagerBuilder::EP_EnabledOnOptLevel0, addBoundsCheckingPass);
_______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits