diff options
author | Vedant Kumar <vsk@apple.com> | 2017-02-25 06:35:45 +0000 |
---|---|---|
committer | Vedant Kumar <vsk@apple.com> | 2017-02-25 06:35:45 +0000 |
commit | 502bbfafcaca191f13576ce8eb767c96c7b510a5 (patch) | |
tree | 5213cb9b998c7dc51240222d5f0c0cd0d6a95ba7 /clang/lib/CodeGen/CodeGenFunction.h | |
parent | 4284ce1348e075ddf5be18a3e94946a9a425afa6 (diff) | |
download | bcm5719-llvm-502bbfafcaca191f13576ce8eb767c96c7b510a5.tar.gz bcm5719-llvm-502bbfafcaca191f13576ce8eb767c96c7b510a5.zip |
Retry: [profiling] Fix profile counter increment when emitting selects (PR32019)
2nd attempt: the first was in r296231, but it had a use after lifetime
bug.
Clang has logic to lower certain conditional expressions directly into llvm
select instructions. However, it does not emit the correct profile counter
increment as it does this: it emits an unconditional increment of the counter
for the 'then branch', even if the value selected is from the 'else branch'
(this is PR32019).
That means, given the following snippet, we would report that "0" is selected
twice, and that "1" is never selected:
int f1(int x) {
return x ? 0 : 1;
^2 ^0
}
f1(0);
f1(1);
Fix the problem by using the instrprof_increment_step intrinsic to do the
proper increment.
llvm-svn: 296245
Diffstat (limited to 'clang/lib/CodeGen/CodeGenFunction.h')
-rw-r--r-- | clang/lib/CodeGen/CodeGenFunction.h | 7 |
1 files changed, 4 insertions, 3 deletions
diff --git a/clang/lib/CodeGen/CodeGenFunction.h b/clang/lib/CodeGen/CodeGenFunction.h index 72105802b45..e011c1167fd 100644 --- a/clang/lib/CodeGen/CodeGenFunction.h +++ b/clang/lib/CodeGen/CodeGenFunction.h @@ -1127,10 +1127,11 @@ private: uint64_t LoopCount); public: - /// Increment the profiler's counter for the given statement. - void incrementProfileCounter(const Stmt *S) { + /// Increment the profiler's counter for the given statement by \p StepV. + /// If \p StepV is null, the default increment is 1. + void incrementProfileCounter(const Stmt *S, llvm::Value *StepV = nullptr) { if (CGM.getCodeGenOpts().hasProfileClangInstr()) - PGO.emitCounterIncrement(Builder, S); + PGO.emitCounterIncrement(Builder, S, StepV); PGO.setCurrentStmt(S); } |