CodeQL / Analyze (actions) (push) Canceled after 0s
CodeQL / Analyze (python) (push) Canceled after 0s
pre-commit / pre-commit (push) Canceled after 0s
Multi-Arch CI / setup (push) Canceled after 0s
Publish build_manylinux_x86_64 images / publish_build_manylinux_x86_64 (push) Canceled after 0s
Setup (Multi-Arch) / setup (push) Canceled after 0s
Multi-Arch CI / Linux::${{ fromJSON(needs.setup.outputs.linux_build_config || '{}').build_variant_label || 'skip' }} (push) Canceled after 0s
Publish TheRock Docker image / build-and-push-image (push) Canceled after 0s
Publish no_rocm_image_ubi10 image / publish_no_rocm_image_ubi10 (push) Canceled after 0s
Multi-Arch CI / Windows::${{ fromJSON(needs.setup.outputs.windows_build_config || '{}').build_variant_label || 'skip' }} (push) Canceled after 0s
Publish TheRock Docker image / build-and-push-image (push) Canceled after 0s
Multi-Arch CI / Manifest Diff (push) Canceled after 0s
TheRock Manifest Diff Report / Generate Manifest Diff Report (push) Canceled after 0s
Multi-Arch CI / CI Summary (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04 images / publish_no_rocm_image_ubuntu24_04 (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04_ocl_rt images / publish_no_rocm_image_ubuntu24_04_ocl_rt (push) Canceled after 0s
Publish TheRock Docker image / build-and-push-image (push) Canceled after 0s
Publish TheRock Docker image / build-and-push-image (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04 images / publish_no_rocm_image_ubuntu24_04_rocgdb (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04_rocgdb images / publish_no_rocm_image_ubuntu24_04_rocgdb (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04 images / publish_no_rocm_image_ubuntu24_04_ocl_rt (push) Canceled after 0s
Publish TheRock Docker image / build-and-push-image (push) Canceled after 0s
Unit Tests / Unit Tests :: ubuntu-24.04 (push) Canceled after 0s
Unit Tests / Unit Tests :: windows-2022 (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04 images / publish_no_rocm_image_ubuntu24_04_media (push) Canceled after 0s
Unit Tests / Unit Tests Summary (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04 images / publish_no_rocm_image_ubuntu24_04_openmpi (push) Canceled after 0s
66 lines
2.4 KiB
C
66 lines
2.4 KiB
C
// Test __builtin_expect, __builtin_expect_with_probability, and __builtin_unpredictable.
|
|
// Focus: O0 vs O2 CIR output (no cir.expect at O0), and LLVM/OGCG with -O2 -disable-llvm-passes.
|
|
// Builtin call lowering is also covered by builtin_call.cpp.
|
|
//
|
|
// RUN: %clang_cc1 -O0 -triple x86_64-unknown-linux-gnu -fclangir -emit-cir %s -o - | FileCheck %s --check-prefix=CIR-O0
|
|
// CIR-O0-NOT: cir.expect
|
|
// RUN: %clang_cc1 -O2 -triple x86_64-unknown-linux-gnu -fclangir -emit-cir %s -o - | FileCheck %s --check-prefix=CIR-O2
|
|
// RUN: %clang_cc1 -O2 -disable-llvm-passes -triple x86_64-unknown-linux-gnu -fclangir -emit-llvm %s -o - | FileCheck %s --check-prefix=LLVM
|
|
// RUN: %clang_cc1 -O2 -disable-llvm-passes -triple x86_64-unknown-linux-gnu -emit-llvm %s -o - | FileCheck %s --check-prefix=LLVM
|
|
|
|
extern void __attribute__((noinline)) bar(void);
|
|
|
|
void expect(int x) {
|
|
if (__builtin_expect(x, 0))
|
|
bar();
|
|
}
|
|
// CIR-O0: cir.func {{.*}} @expect
|
|
// CIR-O0: cir.if {{%.*}} {
|
|
// CIR-O0: cir.call @bar() : () -> ()
|
|
|
|
// CIR-O2: cir.func {{.*}} @expect
|
|
// CIR-O2: [[EXPECT:%.*]] = cir.expect({{.*}}, {{.*}}) : !s64i
|
|
// CIR-O2: [[EXPECT_BOOL:%.*]] = cir.cast int_to_bool [[EXPECT]] : !s64i -> !cir.bool
|
|
// CIR-O2: cir.if [[EXPECT_BOOL]]
|
|
// CIR-O2: cir.call @bar() : () -> ()
|
|
|
|
// LLVM-LABEL: @expect
|
|
// LLVM: br i1 {{.*}}, label %[[THEN:.*]], label %[[END:.*]]
|
|
// LLVM: [[THEN]]:
|
|
// LLVM: call void @bar()
|
|
|
|
|
|
void expect_with_probability(int x) {
|
|
if (__builtin_expect_with_probability(x, 1, 0.8))
|
|
bar();
|
|
}
|
|
// CIR-O0: cir.func {{.*}} @expect_with_probability
|
|
// CIR-O0: cir.if {{%.*}} {
|
|
// CIR-O0: cir.call @bar() : () -> ()
|
|
|
|
// CIR-O2: cir.func {{.*}} @expect_with_probability
|
|
// CIR-O2: [[EXPECT:%.*]] = cir.expect({{.*}}, {{.*}}, 8.000000e-01) : !s64i
|
|
// CIR-O2: [[EXPECT_BOOL:%.*]] = cir.cast int_to_bool [[EXPECT]] : !s64i -> !cir.bool
|
|
// CIR-O2: cir.if [[EXPECT_BOOL]]
|
|
// CIR-O2: cir.call @bar() : () -> ()
|
|
|
|
// LLVM-LABEL: @expect_with_probability
|
|
// LLVM: br i1 {{.*}}, label %[[THEN:.*]], label %[[END:.*]]
|
|
// LLVM: [[THEN]]:
|
|
// LLVM: call void @bar()
|
|
|
|
|
|
void unpredictable(int x) {
|
|
if (__builtin_unpredictable(x > 1))
|
|
bar();
|
|
}
|
|
// CIR-O0: cir.func {{.*}} @unpredictable
|
|
// CIR-O0: cir.if {{%.*}} {
|
|
// CIR-O0: cir.call @bar() : () -> ()
|
|
|
|
// LLVM-LABEL: @unpredictable
|
|
// LLVM: br i1 {{.*}}, label %[[THEN:.*]], label %[[END:.*]]
|
|
// LLVM: [[THEN]]:
|
|
// LLVM: call void @bar()
|
|
|