fix(joinir): Phase 219 regression fix - ConditionPatternBox

Introduced ConditionPatternBox to detect if condition complexity:
- Simple comparisons (var CmpOp literal): use AST-based if-sum lowerer
- Complex conditions (BinaryOp, etc.): fallback to legacy P3 lowerer

This fixes loop_if_phi.hako which was broken by Phase 219's
is_if_sum_pattern() changes.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
nyash-codex
2025-12-10 03:54:17 +09:00
parent 8f7c6c5637
commit d0d2a30c56
3 changed files with 270 additions and 6 deletions

View File

@ -178,19 +178,27 @@ impl PatternPipelineContext {
///
/// Returns true if:
/// 1. loop_body contains an if statement
/// 2. carrier composition matches if-sum pattern (1 counter + 1-2 accumulators)
/// 2. if condition is a simple comparison (var CmpOp literal) - Phase 219-fix
/// 3. carrier composition matches if-sum pattern (1 counter + 1-2 accumulators)
///
/// This determines whether to use AST-based lowering or legacy PoC lowering.
pub fn is_if_sum_pattern(&self) -> bool {
// Check if loop_body has if statement
let has_if = self.loop_body.as_ref().map_or(false, |body| {
body.iter().any(|stmt| matches!(stmt, ASTNode::If { .. }))
});
if !has_if {
let if_stmt = self.extract_if_statement();
if if_stmt.is_none() {
return false;
}
// Phase 219-fix: Check if if condition is a simple comparison
// Complex conditions (e.g., i % 2 == 1) → fallback to legacy mode
if let Some(ASTNode::If { condition, .. }) = if_stmt {
use crate::mir::join_ir::lowering::condition_pattern::is_simple_comparison;
if !is_simple_comparison(condition) {
// Complex condition → legacy mode (PoC lowering)
return false;
}
}
// Phase 219: Use assignment-based carrier detection
// (1 counter like "i" + 1-2 accumulators like "sum", "count")
use crate::mir::join_ir::lowering::loop_update_summary::analyze_loop_updates_from_ast;