Skip to content

Commit 78f67c7

Browse files
committed
Fix Op::Constant with boolean result type emitting wrong sort
Some SPIR-V compilers emit OpConstant (instead of OpConstantTrue/ OpConstantFalse) for boolean values. The parser only checked for float vs integer, so bool constants fell through to the integer branch and produced (Const N) instead of (BoolConst N). This caused egglog sort mismatches when the value was later used in boolean operations expecting BoolExpr. Check TypeClass::Bool before the float/integer branches so boolean OpConstant values emit (BoolConst 0/1) in the correct BoolExpr sort.
1 parent b8a5f5d commit 78f67c7

1 file changed

Lines changed: 10 additions & 2 deletions

File tree

rust/spirv-tools-opt/src/direct/context.rs

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -170,9 +170,17 @@ impl EgglogContext {
170170
Op::Constant => {
171171
let result_type = inst.result_type?;
172172
let width = self.type_widths.get(&result_type).copied().unwrap_or(32);
173-
let is_float = self.type_class_of_type(result_type) == TypeClass::Float;
173+
let type_class = self.type_class_of_type(result_type);
174174

175-
if is_float {
175+
if type_class == TypeClass::Bool {
176+
// Boolean constant via OpConstant (some compilers use this
177+
// instead of OpConstantTrue/OpConstantFalse)
178+
let value = inst.operands.iter().find_map(|op| match op {
179+
Operand::LiteralBit32(v) => Some(*v),
180+
_ => None,
181+
})?;
182+
format!("(BoolConst {})", if value != 0 { 1 } else { 0 })
183+
} else if type_class == TypeClass::Float {
176184
// Float constant: reinterpret bits as IEEE float for FConst
177185
let float_val: f64 = inst.operands.iter().find_map(|op| match op {
178186
Operand::LiteralBit32(v) => Some(f32::from_bits(*v) as f64),

0 commit comments

Comments
 (0)