Skip to content

Commit d645e16

Browse files
committed
Auto merge of rust-lang#119911 - NCGThompson:is-statically-known, r=oli-obk
Replacement of rust-lang#114390: Add new intrinsic `is_var_statically_known` and optimize pow for powers of two This adds a new intrinsic `is_val_statically_known` that lowers to [``@llvm.is.constant.*`](https://llvm.org/docs/LangRef.html#llvm-is-constant-intrinsic).` It also applies the intrinsic in the int_pow methods to recognize and optimize the idiom `2isize.pow(x)`. See rust-lang#114390 for more discussion. While I have extended the scope of the power of two optimization from rust-lang#114390, I haven't added any new uses for the intrinsic. That can be done in later pull requests. Note: When testing or using the library, be sure to use `--stage 1` or higher. Otherwise, the intrinsic will be a noop and the doctests will be skipped. If you are trying out edits, you may be interested in [`--keep-stage 0`](https://rustc-dev-guide.rust-lang.org/building/suggested.html#faster-builds-with---keep-stage). Fixes rust-lang#47234 Resolves rust-lang#114390 `@Centri3`
2 parents 558d051 + b2a7afd commit d645e16

File tree

2 files changed

+10
-3
lines changed

2 files changed

+10
-3
lines changed

src/context.rs

+4-3
Original file line numberDiff line numberDiff line change
@@ -196,15 +196,16 @@ impl<'gcc, 'tcx> CodegenCx<'gcc, 'tcx> {
196196

197197
let mut functions = FxHashMap::default();
198198
let builtins = [
199-
"__builtin_unreachable", "abort", "__builtin_expect", "__builtin_add_overflow", "__builtin_mul_overflow",
200-
"__builtin_saddll_overflow", /*"__builtin_sadd_overflow",*/ "__builtin_smulll_overflow", /*"__builtin_smul_overflow",*/
199+
"__builtin_unreachable", "abort", "__builtin_expect", /*"__builtin_expect_with_probability",*/
200+
"__builtin_constant_p", "__builtin_add_overflow", "__builtin_mul_overflow", "__builtin_saddll_overflow",
201+
/*"__builtin_sadd_overflow",*/ "__builtin_smulll_overflow", /*"__builtin_smul_overflow",*/
201202
"__builtin_ssubll_overflow", /*"__builtin_ssub_overflow",*/ "__builtin_sub_overflow", "__builtin_uaddll_overflow",
202203
"__builtin_uadd_overflow", "__builtin_umulll_overflow", "__builtin_umul_overflow", "__builtin_usubll_overflow",
203204
"__builtin_usub_overflow", "sqrtf", "sqrt", "__builtin_powif", "__builtin_powi", "sinf", "sin", "cosf", "cos",
204205
"powf", "pow", "expf", "exp", "exp2f", "exp2", "logf", "log", "log10f", "log10", "log2f", "log2", "fmaf",
205206
"fma", "fabsf", "fabs", "fminf", "fmin", "fmaxf", "fmax", "copysignf", "copysign", "floorf", "floor", "ceilf",
206207
"ceil", "truncf", "trunc", "rintf", "rint", "nearbyintf", "nearbyint", "roundf", "round",
207-
"__builtin_expect_with_probability",
208+
208209
];
209210

210211
for builtin in builtins.iter() {

src/intrinsic/mod.rs

+6
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,12 @@ impl<'a, 'gcc, 'tcx> IntrinsicCallMethods<'tcx> for Builder<'a, 'gcc, 'tcx> {
123123
sym::unlikely => {
124124
self.expect(args[0].immediate(), false)
125125
}
126+
sym::is_val_statically_known => {
127+
let a = args[0].immediate();
128+
let builtin = self.context.get_builtin_function("__builtin_constant_p");
129+
let res = self.context.new_call(None, builtin, &[a]);
130+
self.icmp(IntPredicate::IntEQ, res, self.const_i32(0))
131+
}
126132
kw::Try => {
127133
try_intrinsic(
128134
self,

0 commit comments

Comments
 (0)