[InstCombine] Preserve NSW flags for `lshr (mul nuw X, C1), C2 -> mul nuw nsw X,...
[llvm-project.git] / clang / test / CodeGenCXX / pr12251.cpp
blobbd5c85b83f2caf05b9c3d97d45a39c63d8160aaf
1 // RUN: %clang_cc1 %s -triple i386-unknown-unknown -emit-llvm -O1 -relaxed-aliasing -fstrict-enums -std=c++11 -o - | FileCheck %s
2 // RUN: %clang_cc1 %s -triple i386-unknown-unknown -emit-llvm -O1 -relaxed-aliasing -std=c++11 -o - | FileCheck --check-prefix=NO-STRICT-ENUMS %s
4 bool f(bool *x) {
5 return *x;
7 // CHECK-LABEL: define{{.*}} zeroext i1 @_Z1fPb
8 // CHECK: load i8, ptr %{{[^ ]*}}, align 1, !range [[RANGE_i8_0_2:![0-9]+]], !noundef [[NOUNDEF:![0-9]+]]
10 // Only enum-tests follow. Ensure that after the bool test, no further range
11 // metadata shows up when strict enums are disabled.
12 // NO-STRICT-ENUMS-LABEL: define{{.*}} zeroext i1 @_Z1fPb
13 // NO-STRICT-ENUMS: load i8, ptr %{{[^ ]*}}, align 1, !range
14 // NO-STRICT-ENUMS-NOT: !range
16 enum e1 { };
17 e1 g1(e1 *x) {
18 return *x;
20 // CHECK-LABEL: define{{.*}} i32 @_Z2g1P2e1
21 // CHECK: ret i32 %0
23 enum e2 { e2_a = 0 };
24 e2 g2(e2 *x) {
25 return *x;
27 // CHECK-LABEL: define{{.*}} i32 @_Z2g2P2e2
28 // CHECK: ret i32 %0
30 enum e3 { e3_a = 16 };
31 e3 g3(e3 *x) {
32 return *x;
34 // CHECK-LABEL: define{{.*}} i32 @_Z2g3P2e3
35 // CHECK: load i32, ptr %x, align 4, !range [[RANGE_i32_0_32:![0-9]+]], !noundef [[NOUNDEF]]
37 enum e4 { e4_a = -16};
38 e4 g4(e4 *x) {
39 return *x;
41 // CHECK-LABEL: define{{.*}} i32 @_Z2g4P2e4
42 // CHECK: load i32, ptr %x, align 4, !range [[RANGE_i32_m16_16:![0-9]+]], !noundef [[NOUNDEF]]
44 enum e5 { e5_a = -16, e5_b = 16};
45 e5 g5(e5 *x) {
46 return *x;
48 // CHECK-LABEL: define{{.*}} i32 @_Z2g5P2e5
49 // CHECK: load i32, ptr %x, align 4, !range [[RANGE_i32_m32_32:![0-9]+]], !noundef [[NOUNDEF]]
51 enum e6 { e6_a = -1 };
52 e6 g6(e6 *x) {
53 return *x;
55 // CHECK-LABEL: define{{.*}} i32 @_Z2g6P2e6
56 // CHECK: load i32, ptr %x, align 4, !range [[RANGE_i32_m1_1:![0-9]+]], !noundef [[NOUNDEF]]
58 enum e7 { e7_a = -16, e7_b = 2};
59 e7 g7(e7 *x) {
60 return *x;
62 // CHECK-LABEL: define{{.*}} i32 @_Z2g7P2e7
63 // CHECK: load i32, ptr %x, align 4, !range [[RANGE_i32_m16_16]], !noundef [[NOUNDEF]]
65 enum e8 { e8_a = -17};
66 e8 g8(e8 *x) {
67 return *x;
69 // CHECK-LABEL: define{{.*}} i32 @_Z2g8P2e8
70 // CHECK: load i32, ptr %x, align 4, !range [[RANGE_i32_m32_32:![0-9]+]], !noundef [[NOUNDEF]]
72 enum e9 { e9_a = 17};
73 e9 g9(e9 *x) {
74 return *x;
76 // CHECK-LABEL: define{{.*}} i32 @_Z2g9P2e9
77 // CHECK: load i32, ptr %x, align 4, !range [[RANGE_i32_0_32]], !noundef [[NOUNDEF]]
79 enum e10 { e10_a = -16, e10_b = 32};
80 e10 g10(e10 *x) {
81 return *x;
83 // CHECK-LABEL: define{{.*}} i32 @_Z3g10P3e10
84 // CHECK: load i32, ptr %x, align 4, !range [[RANGE_i32_m64_64:![0-9]+]], !noundef [[NOUNDEF]]
86 enum e11 {e11_a = 4294967296 };
87 enum e11 g11(enum e11 *x) {
88 return *x;
90 // CHECK-LABEL: define{{.*}} i64 @_Z3g11P3e11
91 // CHECK: load i64, ptr %x, align {{[84]}}, !range [[RANGE_i64_0_2pow33:![0-9]+]], !noundef [[NOUNDEF]]
93 enum e12 {e12_a = 9223372036854775808U };
94 enum e12 g12(enum e12 *x) {
95 return *x;
97 // CHECK-LABEL: define{{.*}} i64 @_Z3g12P3e12
98 // CHECK: load i64, ptr %x, align {{[84]}}
99 // CHECK-NOT: range
100 // CHECK: ret
102 enum e13 : char {e13_a = -1 };
103 e13 g13(e13 *x) {
104 return *x;
106 // CHECK-LABEL: define{{.*}} signext i8 @_Z3g13P3e13
107 // CHECK: load i8, ptr %x, align 1
108 // CHECK-NOT: range
109 // CHECK: ret
111 enum class e14 {e14_a = 1};
112 e14 g14(e14 *x) {
113 return *x;
115 // CHECK-LABEL: define{{.*}} i32 @_Z3g14P3e14
116 // CHECK: load i32, ptr %x, align 4
117 // CHECK-NOT: range
118 // CHECK: ret
120 enum e15 { e15_a = 2147483648 };
121 e15 g15(e15 *x) {
122 return *x;
124 // CHECK-LABEL: define{{.*}} i32 @_Z3g15P3e15
125 // CHECK: load i32, ptr %x, align 4
126 // CHECK-NOT: range
127 // CHECK: ret
129 enum e16 { e16_a = -2147483648 };
130 e16 g16(e16 *x) {
131 return *x;
133 // CHECK-LABEL: define{{.*}} i32 @_Z3g16P3e16
134 // CHECK: load i32, ptr %x, align 4
135 // CHECK-NOT: range
136 // CHECK: ret
139 // CHECK: [[RANGE_i8_0_2]] = !{i8 0, i8 2}
140 // CHECK: [[NOUNDEF]] = !{}
141 // CHECK: [[RANGE_i32_0_32]] = !{i32 0, i32 32}
142 // CHECK: [[RANGE_i32_m16_16]] = !{i32 -16, i32 16}
143 // CHECK: [[RANGE_i32_m32_32]] = !{i32 -32, i32 32}
144 // CHECK: [[RANGE_i32_m1_1]] = !{i32 -1, i32 1}
145 // CHECK: [[RANGE_i32_m64_64]] = !{i32 -64, i32 64}
146 // CHECK: [[RANGE_i64_0_2pow33]] = !{i64 0, i64 8589934592}