]> granicus.if.org Git - clang/commit
[profiling] Fix profile counter increment when emitting selects (PR32019)
authorVedant Kumar <vsk@apple.com>
Sat, 25 Feb 2017 02:30:03 +0000 (02:30 +0000)
committerVedant Kumar <vsk@apple.com>
Sat, 25 Feb 2017 02:30:03 +0000 (02:30 +0000)
commit83740ef4fd7b2c18bcbca00af68875e2e97aab35
tree0553a89b5a7685c00c68b6afed0fb406f0d93748
parent8989fd32d7473f2f82da784f9f1d50530fe2218b
[profiling] Fix profile counter increment when emitting selects (PR32019)

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.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@296231 91177308-0d34-0410-b5e6-96231b3b80d8
lib/CodeGen/CGExprScalar.cpp
lib/CodeGen/CodeGenFunction.h
lib/CodeGen/CodeGenPGO.cpp
lib/CodeGen/CodeGenPGO.h
test/Profile/c-ternary.c [new file with mode: 0644]