Skip to content

Commit 587c017

Browse files
committed
const folding: select
1 parent 356e3c8 commit 587c017

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
@@ -2927,6 +2927,12 @@ impl<'a, 'tcx> BuilderMethods<'a, 'tcx> for Builder<'a, 'tcx> {
29272927
) -> Self::Value {
29282928
assert_ty_eq!(self, then_val.ty, else_val.ty);
29292929
let result_type = then_val.ty;
2930+
2931+
if let Some(ConstValue::Bool(b)) = self.try_get_const_value(cond) {
2932+
// as we directly return the values, it'll preserve their constness as well
2933+
return if b { then_val } else { else_val };
2934+
}
2935+
29302936
self.emit()
29312937
.select(
29322938
result_type,

0 commit comments

Comments
 (0)