feat(joinir): Phase 222-3 if-sum normalization integration
Phase 222: If Condition Normalization - Part 3
Goal: Integrate normalization into if-sum pattern detection and lowering
Changes:
1. pattern_pipeline.rs (is_if_sum_pattern):
- Updated to use analyze_condition_pattern() + normalize_comparison()
- Added two-step validation:
(a) Pattern must be SimpleComparison
(b) Condition must be normalizable
- Replaced is_simple_comparison() with Phase 222 API
2. loop_with_if_phi_if_sum.rs (extract_loop_condition):
- Added Phase 222 normalization
- Normalize condition to canonical form (var on left)
- Support both literal and variable on right-hand side
- Added mir::CompareOp → join_ir::CompareOp conversion
- Handles:
* Phase 219: var CmpOp literal (e.g., i > 0)
* Phase 222: literal CmpOp var (e.g., 0 < i) → normalized
* Phase 222: var CmpOp var (e.g., i > j)
Status: Integration complete, ready for E2E testing
Next: Phase 222-4 - verify regression tests and add new test cases
This commit is contained in:
@ -189,14 +189,25 @@ impl PatternPipelineContext {
|
||||
return false;
|
||||
}
|
||||
|
||||
// Phase 219-fix: Check if if condition is a simple comparison
|
||||
// Phase 222: Check if if condition is a simple comparison and normalizable
|
||||
// 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) {
|
||||
use crate::mir::join_ir::lowering::condition_pattern::{
|
||||
analyze_condition_pattern, normalize_comparison, ConditionPattern
|
||||
};
|
||||
|
||||
// (a) Pattern check: must be SimpleComparison
|
||||
let pattern = analyze_condition_pattern(condition);
|
||||
if pattern != ConditionPattern::SimpleComparison {
|
||||
// Complex condition → legacy mode (PoC lowering)
|
||||
return false;
|
||||
}
|
||||
|
||||
// (b) Normalization check: must be normalizable
|
||||
if normalize_comparison(condition).is_none() {
|
||||
// Normalization failed → legacy mode
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
// Phase 219: Use assignment-based carrier detection
|
||||
|
||||
Reference in New Issue
Block a user