summaryrefslogtreecommitdiffstats
path: root/clang/test
diff options
context:
space:
mode:
authorVedant Kumar <vsk@apple.com>2017-02-25 02:30:03 +0000
committerVedant Kumar <vsk@apple.com>2017-02-25 02:30:03 +0000
commitc416e99d423ac8c96254985ef8f154d74240235c (patch)
treeedfe947c1d2d045ce938e904b9ecd3e762227b68 /clang/test
parent47926abfa651956b65433a71635a22389b5a298d (diff)
downloadbcm5719-llvm-c416e99d423ac8c96254985ef8f154d74240235c.tar.gz
bcm5719-llvm-c416e99d423ac8c96254985ef8f154d74240235c.zip
[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. llvm-svn: 296231
Diffstat (limited to 'clang/test')
-rw-r--r--clang/test/Profile/c-ternary.c15
1 files changed, 15 insertions, 0 deletions
diff --git a/clang/test/Profile/c-ternary.c b/clang/test/Profile/c-ternary.c
new file mode 100644
index 00000000000..09e83292352
--- /dev/null
+++ b/clang/test/Profile/c-ternary.c
@@ -0,0 +1,15 @@
+// RUN: %clang_cc1 -triple x86_64-apple-macosx10.11.0 -x c %s -o - -emit-llvm -fprofile-instrument=clang | FileCheck %s
+
+// PR32019: Clang can lower some ternary operator expressions to select
+// instructions. Make sure we only increment the profile counter for the
+// condition when the condition evaluates to true.
+// CHECK-LABEL: define i32 @f1
+int f1(int x) {
+// CHECK: [[TOBOOL:%.*]] = icmp ne i32 %1, 0
+// CHECK-NEXT: [[STEP:%.*]] = zext i1 [[TOBOOL]] to i64
+// CHECK-NEXT: [[COUNTER:%.*]] = load i64, i64* getelementptr inbounds ([2 x i64], [2 x i64]* @__profc_f1, i64 0, i64 1)
+// CHECK-NEXT: add i64 [[COUNTER]], [[STEP]]
+// CHECK: [[COND:%.*]] = select i1 [[TOBOOL]], i32 0, i32 1
+ return x ? 0 : 1;
+// CHECK: ret i32 [[COND]]
+}
OpenPOWER on IntegriCloud