# MLIR -- Folders and Constant Propagation

DevFeed: [MLIR -- Folders and Constant Propagation](<https://devfeed.tech/articles/mlir-folders-and-constant-propagation-40474.md>)

Original publisher: [Read original article](<https://www.jeremykun.com/2023/09/11/mlir-folders/>)

Published: 2023-09-11T08:00:00Z

Content type: tutorial

Language: en

Sources: [Jeremy Kun](<https://devfeed.tech/sources/jeremy-kun.md>)

Topics: [Code](<https://devfeed.tech/topics/code.md>), [Computing](<https://devfeed.tech/topics/computing.md>), [Pull Request](<https://devfeed.tech/topics/pull-request.md>)

Tags: [article](<https://devfeed.tech/tags/article.md>), [c-plus-plus](<https://devfeed.tech/tags/c-plus-plus.md>), [canonicalization](<https://devfeed.tech/tags/canonicalization.md>), [code](<https://devfeed.tech/tags/code.md>), [compilers](<https://devfeed.tech/tags/compilers.md>), [folding](<https://devfeed.tech/tags/folding.md>), [heir](<https://devfeed.tech/tags/heir.md>), [invariant](<https://devfeed.tech/tags/invariant.md>), [mathematics](<https://devfeed.tech/tags/mathematics.md>), [mlir](<https://devfeed.tech/tags/mlir.md>), [process](<https://devfeed.tech/tags/process.md>), [programming](<https://devfeed.tech/tags/programming.md>)

## AI overview

This tutorial explains how MLIR folding supports sparse conditional constant propagation and canonicalization. It describes adding a constant operation, a materialization hook, and folders for each operation, while distinguishing local canonicalization from propagation through control flow.

## Source excerpt

Table of Contents Last time we saw how to use pre-defined MLIR traits to enable upstream MLIR passes like loop-invariant-code-motion to apply to poly programs. We left out -sccp (sparse conditional constant propagation), and so this time we'll add what is needed to make that pass work. It requires the concept of folding. The code for this article is in this pull request, and as usual the commits are organized to be read in order.