@@ -110,3 +110,43 @@ void assume(bool arg) {
110110// OGCG: define {{.*}}void @_Z6assumeb
111111// OGCG: call void @llvm.assume(i1 %{{.+}})
112112// OGCG: }
113+
114+ void expect (int x, int y) {
115+ __builtin_expect (x, y);
116+ }
117+
118+ // CIR-LABEL: cir.func @_Z6expectii
119+ // CIR: %[[X:.+]] = cir.load align(4) %{{.+}} : !cir.ptr<!s32i>, !s32i
120+ // CIR-NEXT: %[[X_LONG:.+]] = cir.cast(integral, %[[X]] : !s32i), !s64i
121+ // CIR-NEXT: %[[Y:.+]] = cir.load align(4) %{{.+}} : !cir.ptr<!s32i>, !s32i
122+ // CIR-NEXT: %[[Y_LONG:.+]] = cir.cast(integral, %[[Y]] : !s32i), !s64i
123+ // CIR-NEXT: %{{.+}} = cir.expect(%[[X_LONG]], %[[Y_LONG]]) : !s64i
124+ // CIR: }
125+
126+ // LLVM-LABEL: define void @_Z6expectii
127+ // LLVM: %[[X:.+]] = load i32, ptr %{{.+}}, align 4
128+ // LLVM-NEXT: %[[X_LONG:.+]] = sext i32 %[[X]] to i64
129+ // LLVM-NEXT: %[[Y:.+]] = load i32, ptr %{{.+}}, align 4
130+ // LLVM-NEXT: %[[Y_LONG:.+]] = sext i32 %[[Y]] to i64
131+ // LLVM-NEXT: %{{.+}} = call i64 @llvm.expect.i64(i64 %[[X_LONG]], i64 %[[Y_LONG]])
132+ // LLVM: }
133+
134+ void expect_prob (int x, int y) {
135+ __builtin_expect_with_probability (x, y, 0.25 );
136+ }
137+
138+ // CIR-LABEL: cir.func @_Z11expect_probii
139+ // CIR: %[[X:.+]] = cir.load align(4) %{{.+}} : !cir.ptr<!s32i>, !s32i
140+ // CIR-NEXT: %[[X_LONG:.+]] = cir.cast(integral, %[[X]] : !s32i), !s64i
141+ // CIR-NEXT: %[[Y:.+]] = cir.load align(4) %{{.+}} : !cir.ptr<!s32i>, !s32i
142+ // CIR-NEXT: %[[Y_LONG:.+]] = cir.cast(integral, %[[Y]] : !s32i), !s64i
143+ // CIR-NEXT: %{{.+}} = cir.expect(%[[X_LONG]], %[[Y_LONG]], 2.500000e-01) : !s64i
144+ // CIR: }
145+
146+ // LLVM: define void @_Z11expect_probii
147+ // LLVM: %[[X:.+]] = load i32, ptr %{{.+}}, align 4
148+ // LLVM-NEXT: %[[X_LONG:.+]] = sext i32 %[[X]] to i64
149+ // LLVM-NEXT: %[[Y:.+]] = load i32, ptr %{{.+}}, align 4
150+ // LLVM-NEXT: %[[Y_LONG:.+]] = sext i32 %[[Y]] to i64
151+ // LLVM-NEXT: %{{.+}} = call i64 @llvm.expect.with.probability.i64(i64 %[[X_LONG]], i64 %[[Y_LONG]], double 2.500000e-01)
152+ // LLVM: }
0 commit comments