Skip to content

Commit db440f0

Browse files
committed
const folding: select
1 parent 258c189 commit db440f0

File tree

1 file changed

+8
-0
lines changed

1 file changed

+8
-0
lines changed

crates/rustc_codegen_spirv/src/builder/builder_methods.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3071,6 +3071,14 @@ impl<'a, 'tcx> BuilderMethods<'a, 'tcx> for Builder<'a, 'tcx> {
30713071
) -> Self::Value {
30723072
assert_ty_eq!(self, then_val.ty, else_val.ty);
30733073
let result_type = then_val.ty;
3074+
3075+
if let Some(const_cond) = self.try_get_const_int_value(cond) {
3076+
if let ConstValue::Bool(b) = const_cond {
3077+
// as we directly return the values, it'll preserve their constness as well
3078+
return if b { then_val } else { else_val };
3079+
}
3080+
}
3081+
30743082
self.emit()
30753083
.select(
30763084
result_type,

0 commit comments

Comments
 (0)