51 lines · c
1// RUN: %clang_cc1 -triple x86_64-unknown-linux-gnu -fclangir -emit-cir %s -o %t.cir2// RUN: FileCheck --check-prefix=CIR --input-file=%t.cir %s3// RUN: %clang_cc1 -triple x86_64-unknown-linux-gnu -fclangir -emit-llvm %s -o %t-cir.ll4// RUN: FileCheck --check-prefix=LLVM --input-file=%t-cir.ll %s5// RUN: %clang_cc1 -triple x86_64-unknown-linux-gnu -emit-llvm %s -o %t.ll6// RUN: FileCheck --check-prefix=OGCG --input-file=%t.ll %s7 8int addrcmp(const void* a, const void* b) {9 // CIR-LABEL: addrcmp10 // CIR: %[[R:.*]] = cir.ptr_diff11 // CIR: cir.cast integral %[[R]] : !s64i -> !s32i12 13 // LLVM-LABEL: define dso_local i32 @addrcmp(14 // LLVM: %[[PTR_A:.*]] = ptrtoint ptr {{.*}} to i6415 // LLVM: %[[PTR_B:.*]] = ptrtoint ptr {{.*}} to i6416 // LLVM: %[[SUB:.*]] = sub i64 %[[PTR_A]], %[[PTR_B]]17 // LLVM-NOT: sdiv18 // LLVM: trunc i64 %[[SUB]] to i3219 20 // OGCG-LABEL: define dso_local i32 @addrcmp(21 // OGCG: %[[PTR_A:.*]] = ptrtoint ptr {{.*}} to i6422 // OGCG: %[[PTR_B:.*]] = ptrtoint ptr {{.*}} to i6423 // OGCG: %[[SUB:.*]] = sub i64 %[[PTR_A]], %[[PTR_B]]24 // OGCG-NOT: sdiv25 // OGCG: trunc i64 %[[SUB]] to i3226 return *(const void**)a - *(const void**)b;27}28 29unsigned long long test_ptr_diff(int *a, int* b) {30 // CIR-LABEL: test_ptr_diff31 // CIR: %[[D:.*]] = cir.ptr_diff {{.*}} : !cir.ptr<!s32i> -> !s64i32 // CIR: %[[U:.*]] = cir.cast integral %[[D]] : !s64i -> !u64i33 // CIR: cir.return {{.*}} : !u64i34 35 // LLVM-LABEL: define dso_local i64 @test_ptr_diff(36 // LLVM: %[[IA:.*]] = ptrtoint ptr %{{.*}} to i6437 // LLVM: %[[IB:.*]] = ptrtoint ptr %{{.*}} to i6438 // LLVM: %[[SUB:.*]] = sub i64 %[[IA]], %[[IB]]39 // LLVM: %[[Q:.*]] = sdiv exact i64 %[[SUB]], 440 // LLVM: store i64 %[[Q]], ptr %[[RETADDR:.*]], align41 // LLVM: %[[RETLOAD:.*]] = load i64, ptr %[[RETADDR]], align42 // LLVM: ret i64 %[[RETLOAD]]43 44 // OGCG-LABEL: define dso_local i64 @test_ptr_diff(45 // OGCG: %[[IA:.*]] = ptrtoint ptr %{{.*}} to i6446 // OGCG: %[[IB:.*]] = ptrtoint ptr %{{.*}} to i6447 // OGCG: %[[SUB:.*]] = sub i64 %[[IA]], %[[IB]]48 // OGCG: %[[Q:.*]] = sdiv exact i64 %[[SUB]], 449 // OGCG: ret i64 %[[Q]]50 return a - b;51}