Skip to content

Commit 5eabf6c

Browse files
committed
const folding: select
1 parent a6e2c48 commit 5eabf6c

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
@@ -3077,6 +3077,12 @@ impl<'a, 'tcx> BuilderMethods<'a, 'tcx> for Builder<'a, 'tcx> {
30773077
) -> Self::Value {
30783078
assert_ty_eq!(self, then_val.ty, else_val.ty);
30793079
let result_type = then_val.ty;
3080+
3081+
if let Some(ConstValue::Bool(b)) = self.try_get_const_value(cond) {
3082+
// as we directly return the values, it'll preserve their constness as well
3083+
return if b { then_val } else { else_val };
3084+
}
3085+
30803086
self.emit()
30813087
.select(
30823088
result_type,

0 commit comments

Comments
 (0)