[InstCombine] Preserve NSW flags for `lshr (mul nuw X, C1), C2 -> mul nuw nsw X,...
[llvm-project.git] / clang / test / CodeGenCXX / builtin-bit-cast.cpp
blob5f2f48b8fff623f73dacedbdf30581977c4fdb94
1 // RUN: %clang_cc1 -std=c++2a -S -emit-llvm -o - -disable-llvm-passes -triple x86_64-apple-macos10.14 %s | FileCheck %s
3 void test_scalar(int &oper) {
4 // CHECK-LABEL: define{{.*}} void @_Z11test_scalarRi
5 __builtin_bit_cast(float, oper);
7 // CHECK: [[OPER:%.*]] = alloca ptr
8 // CHECK: [[REF:%.*]] = load ptr, ptr
9 // CHECK-NEXT: load float, ptr [[REF]]
12 struct two_ints {
13 int x;
14 int y;
17 unsigned long test_aggregate_to_scalar(two_ints &ti) {
18 // CHECK-LABEL: define{{.*}} i64 @_Z24test_aggregate_to_scalarR8two_ints
19 return __builtin_bit_cast(unsigned long, ti);
21 // CHECK: [[TI_ADDR:%.*]] = alloca ptr, align 8
22 // CHECK: [[TI_LOAD:%.*]] = load ptr, ptr [[TI_ADDR]]
23 // CHECK-NEXT: load i64, ptr [[TI_LOAD]]
26 struct two_floats {
27 float x;
28 float y;
31 two_floats test_aggregate_record(two_ints& ti) {
32 // CHECK-LABEL: define{{.*}} <2 x float> @_Z21test_aggregate_recordR8two_int
33 return __builtin_bit_cast(two_floats, ti);
35 // CHECK: [[RETVAL:%.*]] = alloca %struct.two_floats, align 4
36 // CHECK: [[TI:%.*]] = alloca ptr, align 8
38 // CHECK: [[LOAD_TI:%.*]] = load ptr, ptr [[TI]]
39 // CHECK: call void @llvm.memcpy.p0.p0.i64(ptr align 4 [[RETVAL]], ptr align 4 [[LOAD_TI]]
42 two_floats test_aggregate_array(int (&ary)[2]) {
43 // CHECK-LABEL: define{{.*}} <2 x float> @_Z20test_aggregate_arrayRA2_i
44 return __builtin_bit_cast(two_floats, ary);
46 // CHECK: [[RETVAL:%.*]] = alloca %struct.two_floats, align 4
47 // CHECK: [[ARY:%.*]] = alloca ptr, align 8
49 // CHECK: [[LOAD_ARY:%.*]] = load ptr, ptr [[ARY]]
50 // CHECK: call void @llvm.memcpy.p0.p0.i64(ptr align 4 [[RETVAL]], ptr align 4 [[LOAD_ARY]]
53 two_ints test_scalar_to_aggregate(unsigned long ul) {
54 // CHECK-LABEL: define{{.*}} i64 @_Z24test_scalar_to_aggregatem
55 return __builtin_bit_cast(two_ints, ul);
57 // CHECK: [[TI:%.*]] = alloca %struct.two_ints, align 4
58 // CHECK: call void @llvm.memcpy.p0.p0.i64(ptr align 4 [[TI]]
61 unsigned long test_complex(_Complex unsigned &cu) {
62 // CHECK-LABEL: define{{.*}} i64 @_Z12test_complexRCj
63 return __builtin_bit_cast(unsigned long, cu);
65 // CHECK: [[REF_ALLOCA:%.*]] = alloca ptr, align 8
66 // CHECK-NEXT: store ptr {{.*}}, ptr [[REF_ALLOCA]]
67 // CHECK-NEXT: [[REF:%.*]] = load ptr, ptr [[REF_ALLOCA]]
68 // CHECK-NEXT: load i64, ptr [[REF]], align 4
71 _Complex unsigned test_to_complex(unsigned long &ul) {
72 // CHECK-LABEL: define{{.*}} i64 @_Z15test_to_complexRm
74 return __builtin_bit_cast(_Complex unsigned, ul);
76 // CHECK: [[REF:%.*]] = alloca ptr
77 // CHECK: [[LOAD_REF:%.*]] = load ptr, ptr [[REF]]
80 unsigned long test_array(int (&ary)[2]) {
81 // CHECK-LABEL: define{{.*}} i64 @_Z10test_arrayRA2_i
82 return __builtin_bit_cast(unsigned long, ary);
84 // CHECK: [[REF_ALLOCA:%.*]] = alloca ptr
85 // CHECK: [[LOAD_REF:%.*]] = load ptr, ptr [[REF_ALLOCA]]
86 // CHECK: load i64, ptr [[LOAD_REF]], align 4
89 two_ints test_rvalue_aggregate() {
90 // CHECK-LABEL: define{{.*}} i64 @_Z21test_rvalue_aggregate
91 return __builtin_bit_cast(two_ints, 42ul);
93 // CHECK: [[TI:%.*]] = alloca %struct.two_ints, align 4
94 // CHECK: call void @llvm.memcpy.p0.p0.i64(ptr align 4 [[TI]]