Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 27 additions & 4 deletions src/compiler/codegen/passes/pipeline.jl
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,31 @@ const FMA_RULES = RewriteRule[

fma_fusion_pass!(sci::StructuredIRCode) = rewrite_patterns!(sci, FMA_RULES)

#=============================================================================
Algebraic Simplification (rewrite)
=============================================================================#

# Cancel inverse addi/subi pairs: x+c-c → x, x-c+c → x.
# Repeated ~c binds enforce that both operands are the same value.

const ALGEBRA_RULES = RewriteRule[
@rewrite Intrinsics.subi(Intrinsics.addi(~x, ~c), ~c) => ~x
@rewrite Intrinsics.addi(Intrinsics.subi(~x, ~c), ~c) => ~x
]

algebra_pass!(sci::StructuredIRCode) = rewrite_patterns!(sci, ALGEBRA_RULES)

#=============================================================================
Combined Rule Set
=============================================================================#

const ALL_REWRITE_RULES = RewriteRule[
NORMALIZE_RULES...,
ALGEBRA_RULES...,
SVE_RULES...,
FMA_RULES...,
]

#=============================================================================
Pass Pipeline
=============================================================================#
Expand All @@ -122,10 +147,8 @@ Run the full pass pipeline on a StructuredIRCode. Called for both kernel
and subprogram compilation.
"""
function run_passes!(sci::StructuredIRCode)
# Rewrite passes (order matters: normalize before optimize, SVE before FMA)
normalize_pass!(sci)
scalar_view_elim_pass!(sci)
fma_fusion_pass!(sci)
# All rewrite rules in one fixpoint pass
rewrite_patterns!(sci, ALL_REWRITE_RULES)

# Memory ordering
alias_result = alias_analysis_pass!(sci)
Expand Down
Loading
Loading