Skip to content

Commit 23c4cb6

Browse files
committed
const folding: select
1 parent 62295d3 commit 23c4cb6

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
@@ -2910,6 +2910,12 @@ impl<'a, 'tcx> BuilderMethods<'a, 'tcx> for Builder<'a, 'tcx> {
29102910
) -> Self::Value {
29112911
assert_ty_eq!(self, then_val.ty, else_val.ty);
29122912
let result_type = then_val.ty;
2913+
2914+
if let Some(ConstValue::Bool(b)) = self.try_get_const_value(cond) {
2915+
// as we directly return the values, it'll preserve their constness as well
2916+
return if b { then_val } else { else_val };
2917+
}
2918+
29132919
self.emit()
29142920
.select(
29152921
result_type,

0 commit comments

Comments
 (0)