Skip to content

Commit acdc4b1

Browse files
committed
const folding: select
1 parent 67def6f commit acdc4b1

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

0 commit comments

Comments
 (0)