blob: af7922fa26fa00f98320a305e0c82f53c9f89251 [file] [log] [blame]
Vedant Kumar502bbfa2017-02-25 06:35:45 +00001// RUN: %clang_cc1 -triple x86_64-apple-macosx10.11.0 -x c %s -o - -emit-llvm -fprofile-instrument=clang | FileCheck %s
2
3// PR32019: Clang can lower some ternary operator expressions to select
4// instructions. Make sure we only increment the profile counter for the
5// condition when the condition evaluates to true.
6// CHECK-LABEL: define i32 @f1
7int f1(int x) {
Vedant Kumardcfe34e2017-02-25 07:21:23 +00008// CHECK: [[TOBOOL:%.*]] = icmp ne i32 %{{.*}}, 0
Vedant Kumar502bbfa2017-02-25 06:35:45 +00009// CHECK-NEXT: [[STEP:%.*]] = zext i1 [[TOBOOL]] to i64
10// CHECK-NEXT: [[COUNTER:%.*]] = load i64, i64* getelementptr inbounds ([2 x i64], [2 x i64]* @__profc_f1, i64 0, i64 1)
11// CHECK-NEXT: add i64 [[COUNTER]], [[STEP]]
12// CHECK: [[COND:%.*]] = select i1 [[TOBOOL]], i32 0, i32 1
13 return x ? 0 : 1;
14// CHECK: ret i32 [[COND]]
15}