Skip to content

Commit ed633c1

Browse files
Firestar99eddyb
authored andcommitted
const folding: select
1 parent 345186c commit ed633c1

File tree

1 file changed

+6
-0
lines changed

1 file changed

+6
-0
lines changed

crates/rustc_codegen_spirv/src/builder/builder_methods.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2903,6 +2903,12 @@ impl<'a, 'tcx> BuilderMethods<'a, 'tcx> for Builder<'a, 'tcx> {
29032903
) -> Self::Value {
29042904
assert_ty_eq!(self, then_val.ty, else_val.ty);
29052905
let result_type = then_val.ty;
2906+
2907+
if let Some(ConstValue::Bool(b)) = self.try_get_const_value(cond) {
2908+
// as we directly return the values, it'll preserve their constness as well
2909+
return if b { then_val } else { else_val };
2910+
}
2911+
29062912
self.emit()
29072913
.select(
29082914
result_type,

0 commit comments

Comments
 (0)