Skip to content

Instantly share code, notes, and snippets.

@saulshanabrook
Created September 24, 2026 21:03
Show Gist options
  • Select an option

  • Save saulshanabrook/9058c3dc63883cc6ec1d6e825e658b6a to your computer and use it in GitHub Desktop.

Select an option

Save saulshanabrook/9058c3dc63883cc6ec1d6e825e658b6a to your computer and use it in GitHub Desktop.
DialEgg: 11 captured blocks lacking derived proof queries — original exports, self-contained replays, MLIR, hashes and license

DialEgg exports without derived proof queries

This bundle contains all 11 remaining normal-only DialEgg replay identities: three image_conversion calls, five vector_norm calls, and three polynomial calls. The original source is Aziz Zayed et al.'s DialEgg CGO artifact, revision 4d0d522e98c15becdc5e7d711348cb0891ff0d44, distributed under Apache-2.0 (included as LICENSE.txt). The manifest records each source alias and exact hashes.

Files ending -normal-only.egg are self-contained current-syntax replays. original-*.egg are the unchanged frontend exports; original-base.egg is their unchanged shared prelude (restore it as src/base.egg for the original syntax). The three .mlir files are the original application inputs.

The current-syntax copies inline that prelude, modernize e-class-producing function declarations to constructors, distinguish top-level globals with $, and supply :merge old on the prelude's primitive-valued lookup functions. Original seeds, rewrite rules, costs, schedules and extraction roots remain. No proof query or artificial computation was added. All 11 replay files were regenerated byte-for-byte from the raw exports during this issue preparation. The source capture hook saves every invocation before exporter filename reuse and stops before the external engine/reconstruction phase; it does not synthesize replacement operations.

Reproduce / inspect

With the egglog-encoding release executable, run any current-syntax file:

cargo build --release --bin egglog-experimental
./target/release/egglog-experimental PATH/dialegg-image_conversion-002-normal-only.egg

Inspect the initial let bindings, rules ruleset and extract roots. For example, image_conversion-002 has constants and opaque Values but no arith_divsi node; its only rewrite requires arith_divsi. The unchanged prelude has no active rules. The other applications have the analogous absent rewrite inputs described below. A proof-extraction run with no (check ...) is not evidence of useful extracted proof work. This is a benchmark-query gap, not a reproduced proof-engine panic.

The audited executable SHA-256 was 4e93e5a51eb859da8843fc3cda5e27cb09e00f19bcf410919017082c6d38b2a1 in a dirty checkout at egglog-encoding HEAD fdd4eac12c1318c578badbf5d1299e0e3eb4e6c0. This issue preparation rechecked source and replay identities; it did not rerun engines or add benchmark measurements. Rebuilding HEAD alone is not claimed to reproduce that binary hash.

Why queries are absent

  • image_conversion: no arith_divsi seed, required by its division-to-shift rule.
  • vector_norm: no arith_divf or math_sqrt seed, required by its reciprocal-square-root rule.
  • polynomial: no arith_addf, arith_mulf or math_powf seed, required by every optimization rule.

Four calls have no extraction roots. The other seven extract already seeded constants or ordinary calls. Those equalities would hold before saturation. We have not substituted tautologies, extra seeds, or new transformation rules.

Application Zero-based call Exported function Extraction roots
image_conversion 0 blackhole4k_func.func 0
image_conversion 1 blackhole4kgray_func.func 0
image_conversion 2 main_func.func 7
vector_norm 0 fillRandomF64Tensor2D_func.func 3
vector_norm 1 normalize_distance_vectors_func.func 4
vector_norm 2 blackbox_func.func 0
vector_norm 3 main_func.func 5
vector_norm 4 fast_inv_sqrt_func.func 4
polynomial 0 fillRandomF64Tensor2D_func.func 3
polynomial 1 blackbox_func.func 0
polynomial 2 main_func.func 8

The desired outcome is either a source-faithful derived query that fails with the original schedule removed, or an explicit no-derived-work classification. If the exporter should preserve additional operations, fix or obtain that source export first. Do not infer a replacement Egglog workload from the application.

(sort IntVec (Vec i64))
(sort FloatVec (Vec f64))
;; Types
(sort Type)
(sort TypeVec (Vec Type))
;; Attrs
(sort Attr)
(sort AttrDict (Map String Attr))
(sort AttrVec (Vec Attr))
(datatype AttrPair (NamedAttr String Attr) (ValueAttr Attr))
;; Op
;; Usage:
;; (<op_variant> <operand1> <operand2> ... <operandN> <attr1> <attr2> ... <attrM> <region1> <region2> ... <regionR> <type>)
(datatype Op
(Value i64 Type)
(OpaqueOp i64 TypeVec)
(NoOp)
)
(sort OpVec (Vec Op))
(datatype Block (Blk OpVec))
(sort BlockVec (Vec Block))
(datatype Region (Reg BlockVec))
(sort RegionVec (Vec Region))
;; helper functions
(function type-of (Op) Type :merge old)
(function dims (Type) IntVec :merge old)
;;;; builtin dialect ;;;;
;; Types
(constructor F16 () Type)
(constructor F32 () Type)
(constructor F64 () Type)
(constructor F80 () Type)
(constructor F128 () Type)
(constructor I1 () Type)
(constructor I4 () Type)
(constructor I8 () Type)
(constructor I16 () Type)
(constructor I32 () Type)
(constructor I64 () Type)
(constructor Int (i64) Type)
(constructor SInt (i64) Type)
(constructor UInt (i64) Type)
(constructor OtherInt (String) Type)
(constructor Index () Type)
(constructor None () Type)
(constructor Complex (Type) Type)
(constructor Tuple (TypeVec) Type)
(constructor Function (TypeVec TypeVec) Type)
(constructor Vector (IntVec Type) Type)
(constructor RankedTensor (IntVec Type) Type)
(constructor UnrankedTensor (Type) Type)
(constructor OpaqueType (String String) Type)
; Dynamic RankedTensor type
; (datatype Dimension
; (Dyn)
; (D i64)
; )
; (sort DimVec (Vec Dimension))
; (function DynRankedTensor (DimVec Type) Type)
; (rule ((= ?t (RankedTensor ?dims ?tp))) ((set (dims ?t) ?dims)))
;; Attrs
(constructor NoAttr () Attr)
(constructor IntegerAttr (i64 Type) Attr)
(constructor FloatAttr (f64 Type) Attr)
(constructor StringAttr (String) Attr)
(constructor UnitAttr () Attr)
(constructor TypeAttr (Type) Attr)
(constructor ArrayAttr (AttrVec) Attr)
(constructor DenseIntArrayAttr (i64 IntVec Type) Attr)
(constructor DenseFloatArrayAttr (f64 FloatVec Type) Attr)
(constructor DenseIntElementsAttr (FloatVec Type) Attr)
(constructor DenseFPElementsAttr (FloatVec Type) Attr)
(constructor SymbolRefAttr (String) Attr)
(constructor OpaqueAttr (String String) Attr) ; (<attr> <type-name>)
; DenseResourceElementsAttr
; DenseStringElementsAttr
; DictionaryAttr
; IntegerSetAttr
; OpaqueAttr
; SparseElementsAttr
; SymbolRefAttr
; StridedLayoutAttr
;;;; arith dialect ;;;;
(constructor arith_constant (AttrPair Type) Op)
(constructor arith_divsi (Op Op Type) Op :cost 2)
(constructor arith_shrsi (Op Op Type) Op)
;; OPS HERE ;;
; blackhole4k_func.func
(let $op0 (Value 0 (RankedTensor (vec-of 3840 2160 3) (I64))))
(let $op1 (Value 1 (None)))
;; RULES HERE ;;
(ruleset rules)
(rule ; division by a power of 2 is equivalent to right shift
((= ?lhs (arith_divsi ?x (arith_constant (NamedAttr "value" (IntegerAttr ?n ?t)) ?t) ?t)) ; x / n
(= ?lgn (log2 ?n)) ; if n = 2^k, then k = log2(n)
(= ?n (<< 1 ?lgn))) ; check if n is a power of 2
((union ?lhs (arith_shrsi ?x (arith_constant (NamedAttr "value" (IntegerAttr ?lgn ?t)) ?t) ?t))) ; x / n = x >> lgn
:ruleset rules
)
(run-schedule (saturate rules))
;; EXTRACTS HERE ;;
(sort IntVec (Vec i64))
(sort FloatVec (Vec f64))
;; Types
(sort Type)
(sort TypeVec (Vec Type))
;; Attrs
(sort Attr)
(sort AttrDict (Map String Attr))
(sort AttrVec (Vec Attr))
(datatype AttrPair (NamedAttr String Attr) (ValueAttr Attr))
;; Op
;; Usage:
;; (<op_variant> <operand1> <operand2> ... <operandN> <attr1> <attr2> ... <attrM> <region1> <region2> ... <regionR> <type>)
(datatype Op
(Value i64 Type)
(OpaqueOp i64 TypeVec)
(NoOp)
)
(sort OpVec (Vec Op))
(datatype Block (Blk OpVec))
(sort BlockVec (Vec Block))
(datatype Region (Reg BlockVec))
(sort RegionVec (Vec Region))
;; helper functions
(function type-of (Op) Type :merge old)
(function dims (Type) IntVec :merge old)
;;;; builtin dialect ;;;;
;; Types
(constructor F16 () Type)
(constructor F32 () Type)
(constructor F64 () Type)
(constructor F80 () Type)
(constructor F128 () Type)
(constructor I1 () Type)
(constructor I4 () Type)
(constructor I8 () Type)
(constructor I16 () Type)
(constructor I32 () Type)
(constructor I64 () Type)
(constructor Int (i64) Type)
(constructor SInt (i64) Type)
(constructor UInt (i64) Type)
(constructor OtherInt (String) Type)
(constructor Index () Type)
(constructor None () Type)
(constructor Complex (Type) Type)
(constructor Tuple (TypeVec) Type)
(constructor Function (TypeVec TypeVec) Type)
(constructor Vector (IntVec Type) Type)
(constructor RankedTensor (IntVec Type) Type)
(constructor UnrankedTensor (Type) Type)
(constructor OpaqueType (String String) Type)
; Dynamic RankedTensor type
; (datatype Dimension
; (Dyn)
; (D i64)
; )
; (sort DimVec (Vec Dimension))
; (function DynRankedTensor (DimVec Type) Type)
; (rule ((= ?t (RankedTensor ?dims ?tp))) ((set (dims ?t) ?dims)))
;; Attrs
(constructor NoAttr () Attr)
(constructor IntegerAttr (i64 Type) Attr)
(constructor FloatAttr (f64 Type) Attr)
(constructor StringAttr (String) Attr)
(constructor UnitAttr () Attr)
(constructor TypeAttr (Type) Attr)
(constructor ArrayAttr (AttrVec) Attr)
(constructor DenseIntArrayAttr (i64 IntVec Type) Attr)
(constructor DenseFloatArrayAttr (f64 FloatVec Type) Attr)
(constructor DenseIntElementsAttr (FloatVec Type) Attr)
(constructor DenseFPElementsAttr (FloatVec Type) Attr)
(constructor SymbolRefAttr (String) Attr)
(constructor OpaqueAttr (String String) Attr) ; (<attr> <type-name>)
; DenseResourceElementsAttr
; DenseStringElementsAttr
; DictionaryAttr
; IntegerSetAttr
; OpaqueAttr
; SparseElementsAttr
; SymbolRefAttr
; StridedLayoutAttr
;;;; arith dialect ;;;;
(constructor arith_constant (AttrPair Type) Op)
(constructor arith_divsi (Op Op Type) Op :cost 2)
(constructor arith_shrsi (Op Op Type) Op)
;; OPS HERE ;;
; blackhole4kgray_func.func
(let $op0 (Value 0 (RankedTensor (vec-of 3840 2160) (I64))))
(let $op1 (Value 1 (None)))
;; RULES HERE ;;
(ruleset rules)
(rule ; division by a power of 2 is equivalent to right shift
((= ?lhs (arith_divsi ?x (arith_constant (NamedAttr "value" (IntegerAttr ?n ?t)) ?t) ?t)) ; x / n
(= ?lgn (log2 ?n)) ; if n = 2^k, then k = log2(n)
(= ?n (<< 1 ?lgn))) ; check if n is a power of 2
((union ?lhs (arith_shrsi ?x (arith_constant (NamedAttr "value" (IntegerAttr ?lgn ?t)) ?t) ?t))) ; x / n = x >> lgn
:ruleset rules
)
(run-schedule (saturate rules))
;; EXTRACTS HERE ;;
(sort IntVec (Vec i64))
(sort FloatVec (Vec f64))
;; Types
(sort Type)
(sort TypeVec (Vec Type))
;; Attrs
(sort Attr)
(sort AttrDict (Map String Attr))
(sort AttrVec (Vec Attr))
(datatype AttrPair (NamedAttr String Attr) (ValueAttr Attr))
;; Op
;; Usage:
;; (<op_variant> <operand1> <operand2> ... <operandN> <attr1> <attr2> ... <attrM> <region1> <region2> ... <regionR> <type>)
(datatype Op
(Value i64 Type)
(OpaqueOp i64 TypeVec)
(NoOp)
)
(sort OpVec (Vec Op))
(datatype Block (Blk OpVec))
(sort BlockVec (Vec Block))
(datatype Region (Reg BlockVec))
(sort RegionVec (Vec Region))
;; helper functions
(function type-of (Op) Type :merge old)
(function dims (Type) IntVec :merge old)
;;;; builtin dialect ;;;;
;; Types
(constructor F16 () Type)
(constructor F32 () Type)
(constructor F64 () Type)
(constructor F80 () Type)
(constructor F128 () Type)
(constructor I1 () Type)
(constructor I4 () Type)
(constructor I8 () Type)
(constructor I16 () Type)
(constructor I32 () Type)
(constructor I64 () Type)
(constructor Int (i64) Type)
(constructor SInt (i64) Type)
(constructor UInt (i64) Type)
(constructor OtherInt (String) Type)
(constructor Index () Type)
(constructor None () Type)
(constructor Complex (Type) Type)
(constructor Tuple (TypeVec) Type)
(constructor Function (TypeVec TypeVec) Type)
(constructor Vector (IntVec Type) Type)
(constructor RankedTensor (IntVec Type) Type)
(constructor UnrankedTensor (Type) Type)
(constructor OpaqueType (String String) Type)
; Dynamic RankedTensor type
; (datatype Dimension
; (Dyn)
; (D i64)
; )
; (sort DimVec (Vec Dimension))
; (function DynRankedTensor (DimVec Type) Type)
; (rule ((= ?t (RankedTensor ?dims ?tp))) ((set (dims ?t) ?dims)))
;; Attrs
(constructor NoAttr () Attr)
(constructor IntegerAttr (i64 Type) Attr)
(constructor FloatAttr (f64 Type) Attr)
(constructor StringAttr (String) Attr)
(constructor UnitAttr () Attr)
(constructor TypeAttr (Type) Attr)
(constructor ArrayAttr (AttrVec) Attr)
(constructor DenseIntArrayAttr (i64 IntVec Type) Attr)
(constructor DenseFloatArrayAttr (f64 FloatVec Type) Attr)
(constructor DenseIntElementsAttr (FloatVec Type) Attr)
(constructor DenseFPElementsAttr (FloatVec Type) Attr)
(constructor SymbolRefAttr (String) Attr)
(constructor OpaqueAttr (String String) Attr) ; (<attr> <type-name>)
; DenseResourceElementsAttr
; DenseStringElementsAttr
; DictionaryAttr
; IntegerSetAttr
; OpaqueAttr
; SparseElementsAttr
; SymbolRefAttr
; StridedLayoutAttr
;;;; arith dialect ;;;;
(constructor arith_constant (AttrPair Type) Op)
(constructor arith_divsi (Op Op Type) Op :cost 2)
(constructor arith_shrsi (Op Op Type) Op)
;; OPS HERE ;;
; main_func.func
(let $op0 (arith_constant (NamedAttr "value" (IntegerAttr 100 (I64))) (I64)))
(let $op1 (Value 1 (RankedTensor (vec-of 3840 2160 3) (I64))))
(let $op2 (Value 2 (RankedTensor (vec-of 3840 2160 3) (I64))))
(let $op3 (Value 3 (RankedTensor (vec-of 3840 2160 3) (I64))))
(let $op4 (Value 4 (I64)))
(let $op5 (arith_constant (NamedAttr "value" (IntegerAttr 0 (Index))) (Index)))
(let $op6 (arith_constant (NamedAttr "value" (IntegerAttr 1 (Index))) (Index)))
(let $op7 (arith_constant (NamedAttr "value" (IntegerAttr 2 (Index))) (Index)))
(let $op8 (arith_constant (NamedAttr "value" (IntegerAttr 3840 (Index))) (Index)))
(let $op9 (arith_constant (NamedAttr "value" (IntegerAttr 2160 (Index))) (Index)))
(let $op10 (Value 10 (RankedTensor (vec-of 3840 2160) (I64))))
(let $op11 (Value 11 (RankedTensor (vec-of 3840 2160) (I64))))
(let $op12 (Value 12 (I64)))
(let $op13 (Value 13 (RankedTensor (vec-of 3840 2160) (I64))))
(let $op14 (Value 14 (None)))
(let $op15 (Value 15 (None)))
(let $op16 (arith_constant (NamedAttr "value" (IntegerAttr 0 (I64))) (I64)))
(let $op17 (Value 17 (None)))
;; RULES HERE ;;
(ruleset rules)
(rule ; division by a power of 2 is equivalent to right shift
((= ?lhs (arith_divsi ?x (arith_constant (NamedAttr "value" (IntegerAttr ?n ?t)) ?t) ?t)) ; x / n
(= ?lgn (log2 ?n)) ; if n = 2^k, then k = log2(n)
(= ?n (<< 1 ?lgn))) ; check if n is a power of 2
((union ?lhs (arith_shrsi ?x (arith_constant (NamedAttr "value" (IntegerAttr ?lgn ?t)) ?t) ?t))) ; x / n = x >> lgn
:ruleset rules
)
(run-schedule (saturate rules))
;; EXTRACTS HERE ;;
(extract $op0)
(extract $op5)
(extract $op6)
(extract $op7)
(extract $op8)
(extract $op9)
(extract $op16)
(sort IntVec (Vec i64))
(sort FloatVec (Vec f64))
;; Types
(sort Type)
(sort TypeVec (Vec Type))
;; Attrs
(sort Attr)
(sort AttrDict (Map String Attr))
(sort AttrVec (Vec Attr))
(datatype AttrPair (NamedAttr String Attr) (ValueAttr Attr))
;; Op
;; Usage:
;; (<op_variant> <operand1> <operand2> ... <operandN> <attr1> <attr2> ... <attrM> <region1> <region2> ... <regionR> <type>)
(datatype Op
(Value i64 Type)
(OpaqueOp i64 TypeVec)
(NoOp)
)
(sort OpVec (Vec Op))
(datatype Block (Blk OpVec))
(sort BlockVec (Vec Block))
(datatype Region (Reg BlockVec))
(sort RegionVec (Vec Region))
;; helper functions
(function type-of (Op) Type :merge old)
(function dims (Type) IntVec :merge old)
;;;; builtin dialect ;;;;
;; Types
(constructor F16 () Type)
(constructor F32 () Type)
(constructor F64 () Type)
(constructor F80 () Type)
(constructor F128 () Type)
(constructor I1 () Type)
(constructor I4 () Type)
(constructor I8 () Type)
(constructor I16 () Type)
(constructor I32 () Type)
(constructor I64 () Type)
(constructor Int (i64) Type)
(constructor SInt (i64) Type)
(constructor UInt (i64) Type)
(constructor OtherInt (String) Type)
(constructor Index () Type)
(constructor None () Type)
(constructor Complex (Type) Type)
(constructor Tuple (TypeVec) Type)
(constructor Function (TypeVec TypeVec) Type)
(constructor Vector (IntVec Type) Type)
(constructor RankedTensor (IntVec Type) Type)
(constructor UnrankedTensor (Type) Type)
(constructor OpaqueType (String String) Type)
; Dynamic RankedTensor type
; (datatype Dimension
; (Dyn)
; (D i64)
; )
; (sort DimVec (Vec Dimension))
; (function DynRankedTensor (DimVec Type) Type)
; (rule ((= ?t (RankedTensor ?dims ?tp))) ((set (dims ?t) ?dims)))
;; Attrs
(constructor NoAttr () Attr)
(constructor IntegerAttr (i64 Type) Attr)
(constructor FloatAttr (f64 Type) Attr)
(constructor StringAttr (String) Attr)
(constructor UnitAttr () Attr)
(constructor TypeAttr (Type) Attr)
(constructor ArrayAttr (AttrVec) Attr)
(constructor DenseIntArrayAttr (i64 IntVec Type) Attr)
(constructor DenseFloatArrayAttr (f64 FloatVec Type) Attr)
(constructor DenseIntElementsAttr (FloatVec Type) Attr)
(constructor DenseFPElementsAttr (FloatVec Type) Attr)
(constructor SymbolRefAttr (String) Attr)
(constructor OpaqueAttr (String String) Attr) ; (<attr> <type-name>)
; DenseResourceElementsAttr
; DenseStringElementsAttr
; DictionaryAttr
; IntegerSetAttr
; OpaqueAttr
; SparseElementsAttr
; SymbolRefAttr
; StridedLayoutAttr
;;;; arith dialect ;;;;
;; Attrs
(datatype FastMathFlags (none) (reassoc) (nnan) (fast))
(constructor arith_fastmath (FastMathFlags) Attr)
;; Ops
(constructor arith_constant (AttrPair Type) Op)
(constructor arith_mulf (Op Op AttrPair Type) Op :cost 100)
(constructor arith_addf (Op Op AttrPair Type) Op)
;;;; math dialect ;;;;
(constructor math_powf (Op Op AttrPair Type) Op :cost 100000)
;; OPS HERE ;;
; fillRandomF64Tensor2D_func.func
(let $op0 (Value 0 (RankedTensor (vec-of -9223372036854775808 -9223372036854775808) (F64))))
(let $op1 (arith_constant (NamedAttr "value" (IntegerAttr 0 (I32))) (I32)))
(let $op2 (arith_constant (NamedAttr "value" (FloatAttr -10.0 (F64))) (F64)))
(let $op3 (arith_constant (NamedAttr "value" (FloatAttr 10.0 (F64))) (F64)))
(let $op4 (Value 4 (RankedTensor (vec-of -9223372036854775808 -9223372036854775808) (F64))))
(let $op5 (Value 5 (None)))
;; RULES HERE ;;
(ruleset rules)
; commutative
(rewrite (arith_addf ?x ?y ?a ?t) (arith_addf ?y ?x ?a ?t) :ruleset rules) ; x + y = y + x
(rewrite (arith_mulf ?x ?y ?a ?t) (arith_mulf ?y ?x ?a ?t) :ruleset rules) ; x * y = y * x
; associative
(rewrite ; (x + y) + z = x + (y + z)
(arith_addf (arith_addf ?x ?y ?a ?t) ?z ?a ?t)
(arith_addf ?x (arith_addf ?y ?z ?a ?t) ?a ?t)
:ruleset rules
)
(rewrite ; (x * y) * z = x * (y * z)
(arith_mulf (arith_mulf ?x ?y ?a ?t) ?z ?a ?t)
(arith_mulf ?x (arith_mulf ?y ?z ?a ?t) ?a ?t)
:ruleset rules
)
; identity
(rewrite (arith_mulf ?x (arith_constant (NamedAttr "value" (FloatAttr 1.0 ?t)) ?t) ?a ?t) ?x :ruleset rules) ; x * 1 = x
(rewrite ; x^0 = 1
(math_powf ?x (arith_constant (NamedAttr "value" (FloatAttr 0.0 ?t)) ?t) ?a ?t)
(arith_constant (NamedAttr "value" (FloatAttr 1.0 ?t)) ?t)
:ruleset rules
)
(rule ; x^n = x * x^(n - 1)
((= ?lhs (math_powf ?x (arith_constant (NamedAttr "value" (FloatAttr ?n ?t)) ?t) ?a ?t))
(>= ?n 1.0))
((union
?lhs
(arith_mulf ?x (math_powf ?x (arith_constant (NamedAttr "value" (FloatAttr (- ?n 1.0) ?t)) ?t) ?a ?t) ?a ?t)
))
:ruleset rules
)
; mx + nx = x(m + n)
(rewrite
(arith_addf (arith_mulf ?m ?x ?a ?t) (arith_mulf ?n ?x ?a ?t) ?a ?t)
(arith_mulf ?x (arith_addf ?m ?n ?a ?t) ?a ?t)
:ruleset rules
)
(run-schedule (saturate rules)) ; search 0.017s, apply 0.002s, rebuild 0.006s, total 0.025s
;; EXTRACTS HERE ;;
(extract $op1)
(extract $op2)
(extract $op3)
(sort IntVec (Vec i64))
(sort FloatVec (Vec f64))
;; Types
(sort Type)
(sort TypeVec (Vec Type))
;; Attrs
(sort Attr)
(sort AttrDict (Map String Attr))
(sort AttrVec (Vec Attr))
(datatype AttrPair (NamedAttr String Attr) (ValueAttr Attr))
;; Op
;; Usage:
;; (<op_variant> <operand1> <operand2> ... <operandN> <attr1> <attr2> ... <attrM> <region1> <region2> ... <regionR> <type>)
(datatype Op
(Value i64 Type)
(OpaqueOp i64 TypeVec)
(NoOp)
)
(sort OpVec (Vec Op))
(datatype Block (Blk OpVec))
(sort BlockVec (Vec Block))
(datatype Region (Reg BlockVec))
(sort RegionVec (Vec Region))
;; helper functions
(function type-of (Op) Type :merge old)
(function dims (Type) IntVec :merge old)
;;;; builtin dialect ;;;;
;; Types
(constructor F16 () Type)
(constructor F32 () Type)
(constructor F64 () Type)
(constructor F80 () Type)
(constructor F128 () Type)
(constructor I1 () Type)
(constructor I4 () Type)
(constructor I8 () Type)
(constructor I16 () Type)
(constructor I32 () Type)
(constructor I64 () Type)
(constructor Int (i64) Type)
(constructor SInt (i64) Type)
(constructor UInt (i64) Type)
(constructor OtherInt (String) Type)
(constructor Index () Type)
(constructor None () Type)
(constructor Complex (Type) Type)
(constructor Tuple (TypeVec) Type)
(constructor Function (TypeVec TypeVec) Type)
(constructor Vector (IntVec Type) Type)
(constructor RankedTensor (IntVec Type) Type)
(constructor UnrankedTensor (Type) Type)
(constructor OpaqueType (String String) Type)
; Dynamic RankedTensor type
; (datatype Dimension
; (Dyn)
; (D i64)
; )
; (sort DimVec (Vec Dimension))
; (function DynRankedTensor (DimVec Type) Type)
; (rule ((= ?t (RankedTensor ?dims ?tp))) ((set (dims ?t) ?dims)))
;; Attrs
(constructor NoAttr () Attr)
(constructor IntegerAttr (i64 Type) Attr)
(constructor FloatAttr (f64 Type) Attr)
(constructor StringAttr (String) Attr)
(constructor UnitAttr () Attr)
(constructor TypeAttr (Type) Attr)
(constructor ArrayAttr (AttrVec) Attr)
(constructor DenseIntArrayAttr (i64 IntVec Type) Attr)
(constructor DenseFloatArrayAttr (f64 FloatVec Type) Attr)
(constructor DenseIntElementsAttr (FloatVec Type) Attr)
(constructor DenseFPElementsAttr (FloatVec Type) Attr)
(constructor SymbolRefAttr (String) Attr)
(constructor OpaqueAttr (String String) Attr) ; (<attr> <type-name>)
; DenseResourceElementsAttr
; DenseStringElementsAttr
; DictionaryAttr
; IntegerSetAttr
; OpaqueAttr
; SparseElementsAttr
; SymbolRefAttr
; StridedLayoutAttr
;;;; arith dialect ;;;;
;; Attrs
(datatype FastMathFlags (none) (reassoc) (nnan) (fast))
(constructor arith_fastmath (FastMathFlags) Attr)
;; Ops
(constructor arith_constant (AttrPair Type) Op)
(constructor arith_mulf (Op Op AttrPair Type) Op :cost 100)
(constructor arith_addf (Op Op AttrPair Type) Op)
;;;; math dialect ;;;;
(constructor math_powf (Op Op AttrPair Type) Op :cost 100000)
;; OPS HERE ;;
; blackbox_func.func
(let $op0 (Value 0 (RankedTensor (vec-of 100000000) (F64))))
(let $op1 (Value 1 (None)))
;; RULES HERE ;;
(ruleset rules)
; commutative
(rewrite (arith_addf ?x ?y ?a ?t) (arith_addf ?y ?x ?a ?t) :ruleset rules) ; x + y = y + x
(rewrite (arith_mulf ?x ?y ?a ?t) (arith_mulf ?y ?x ?a ?t) :ruleset rules) ; x * y = y * x
; associative
(rewrite ; (x + y) + z = x + (y + z)
(arith_addf (arith_addf ?x ?y ?a ?t) ?z ?a ?t)
(arith_addf ?x (arith_addf ?y ?z ?a ?t) ?a ?t)
:ruleset rules
)
(rewrite ; (x * y) * z = x * (y * z)
(arith_mulf (arith_mulf ?x ?y ?a ?t) ?z ?a ?t)
(arith_mulf ?x (arith_mulf ?y ?z ?a ?t) ?a ?t)
:ruleset rules
)
; identity
(rewrite (arith_mulf ?x (arith_constant (NamedAttr "value" (FloatAttr 1.0 ?t)) ?t) ?a ?t) ?x :ruleset rules) ; x * 1 = x
(rewrite ; x^0 = 1
(math_powf ?x (arith_constant (NamedAttr "value" (FloatAttr 0.0 ?t)) ?t) ?a ?t)
(arith_constant (NamedAttr "value" (FloatAttr 1.0 ?t)) ?t)
:ruleset rules
)
(rule ; x^n = x * x^(n - 1)
((= ?lhs (math_powf ?x (arith_constant (NamedAttr "value" (FloatAttr ?n ?t)) ?t) ?a ?t))
(>= ?n 1.0))
((union
?lhs
(arith_mulf ?x (math_powf ?x (arith_constant (NamedAttr "value" (FloatAttr (- ?n 1.0) ?t)) ?t) ?a ?t) ?a ?t)
))
:ruleset rules
)
; mx + nx = x(m + n)
(rewrite
(arith_addf (arith_mulf ?m ?x ?a ?t) (arith_mulf ?n ?x ?a ?t) ?a ?t)
(arith_mulf ?x (arith_addf ?m ?n ?a ?t) ?a ?t)
:ruleset rules
)
(run-schedule (saturate rules)) ; search 0.017s, apply 0.002s, rebuild 0.006s, total 0.025s
;; EXTRACTS HERE ;;
(sort IntVec (Vec i64))
(sort FloatVec (Vec f64))
;; Types
(sort Type)
(sort TypeVec (Vec Type))
;; Attrs
(sort Attr)
(sort AttrDict (Map String Attr))
(sort AttrVec (Vec Attr))
(datatype AttrPair (NamedAttr String Attr) (ValueAttr Attr))
;; Op
;; Usage:
;; (<op_variant> <operand1> <operand2> ... <operandN> <attr1> <attr2> ... <attrM> <region1> <region2> ... <regionR> <type>)
(datatype Op
(Value i64 Type)
(OpaqueOp i64 TypeVec)
(NoOp)
)
(sort OpVec (Vec Op))
(datatype Block (Blk OpVec))
(sort BlockVec (Vec Block))
(datatype Region (Reg BlockVec))
(sort RegionVec (Vec Region))
;; helper functions
(function type-of (Op) Type :merge old)
(function dims (Type) IntVec :merge old)
;;;; builtin dialect ;;;;
;; Types
(constructor F16 () Type)
(constructor F32 () Type)
(constructor F64 () Type)
(constructor F80 () Type)
(constructor F128 () Type)
(constructor I1 () Type)
(constructor I4 () Type)
(constructor I8 () Type)
(constructor I16 () Type)
(constructor I32 () Type)
(constructor I64 () Type)
(constructor Int (i64) Type)
(constructor SInt (i64) Type)
(constructor UInt (i64) Type)
(constructor OtherInt (String) Type)
(constructor Index () Type)
(constructor None () Type)
(constructor Complex (Type) Type)
(constructor Tuple (TypeVec) Type)
(constructor Function (TypeVec TypeVec) Type)
(constructor Vector (IntVec Type) Type)
(constructor RankedTensor (IntVec Type) Type)
(constructor UnrankedTensor (Type) Type)
(constructor OpaqueType (String String) Type)
; Dynamic RankedTensor type
; (datatype Dimension
; (Dyn)
; (D i64)
; )
; (sort DimVec (Vec Dimension))
; (function DynRankedTensor (DimVec Type) Type)
; (rule ((= ?t (RankedTensor ?dims ?tp))) ((set (dims ?t) ?dims)))
;; Attrs
(constructor NoAttr () Attr)
(constructor IntegerAttr (i64 Type) Attr)
(constructor FloatAttr (f64 Type) Attr)
(constructor StringAttr (String) Attr)
(constructor UnitAttr () Attr)
(constructor TypeAttr (Type) Attr)
(constructor ArrayAttr (AttrVec) Attr)
(constructor DenseIntArrayAttr (i64 IntVec Type) Attr)
(constructor DenseFloatArrayAttr (f64 FloatVec Type) Attr)
(constructor DenseIntElementsAttr (FloatVec Type) Attr)
(constructor DenseFPElementsAttr (FloatVec Type) Attr)
(constructor SymbolRefAttr (String) Attr)
(constructor OpaqueAttr (String String) Attr) ; (<attr> <type-name>)
; DenseResourceElementsAttr
; DenseStringElementsAttr
; DictionaryAttr
; IntegerSetAttr
; OpaqueAttr
; SparseElementsAttr
; SymbolRefAttr
; StridedLayoutAttr
;;;; arith dialect ;;;;
;; Attrs
(datatype FastMathFlags (none) (reassoc) (nnan) (fast))
(constructor arith_fastmath (FastMathFlags) Attr)
;; Ops
(constructor arith_constant (AttrPair Type) Op)
(constructor arith_mulf (Op Op AttrPair Type) Op :cost 100)
(constructor arith_addf (Op Op AttrPair Type) Op)
;;;; math dialect ;;;;
(constructor math_powf (Op Op AttrPair Type) Op :cost 100000)
;; OPS HERE ;;
; main_func.func
(let $op0 (arith_constant (NamedAttr "value" (IntegerAttr 100000000 (Index))) (Index)))
(let $op1 (arith_constant (NamedAttr "value" (IntegerAttr 4 (Index))) (Index)))
(let $op2 (Value 2 (RankedTensor (vec-of -9223372036854775808 -9223372036854775808) (F64))))
(let $op3 (Value 3 (RankedTensor (vec-of -9223372036854775808 -9223372036854775808) (F64))))
(let $op4 (Value 4 (RankedTensor (vec-of 100000000 4) (F64))))
(let $op5 (Value 5 (I64)))
(let $op6 (arith_constant (NamedAttr "value" (FloatAttr 5.0 (F64))) (F64)))
(let $op7 (arith_constant (NamedAttr "value" (IntegerAttr 0 (Index))) (Index)))
(let $op8 (arith_constant (NamedAttr "value" (IntegerAttr 1 (Index))) (Index)))
(let $op9 (arith_constant (NamedAttr "value" (IntegerAttr 2 (Index))) (Index)))
(let $op10 (arith_constant (NamedAttr "value" (IntegerAttr 3 (Index))) (Index)))
(let $op11 (Value 11 (RankedTensor (vec-of 100000000) (F64))))
(let $op12 (Value 12 (RankedTensor (vec-of 100000000) (F64))))
(let $op13 (Value 13 (I64)))
(let $op14 (Value 14 (RankedTensor (vec-of 100000000) (F64))))
(let $op15 (Value 15 (None)))
(let $op16 (Value 16 (None)))
(let $op17 (arith_constant (NamedAttr "value" (IntegerAttr 0 (I32))) (I32)))
(let $op18 (Value 18 (None)))
;; RULES HERE ;;
(ruleset rules)
; commutative
(rewrite (arith_addf ?x ?y ?a ?t) (arith_addf ?y ?x ?a ?t) :ruleset rules) ; x + y = y + x
(rewrite (arith_mulf ?x ?y ?a ?t) (arith_mulf ?y ?x ?a ?t) :ruleset rules) ; x * y = y * x
; associative
(rewrite ; (x + y) + z = x + (y + z)
(arith_addf (arith_addf ?x ?y ?a ?t) ?z ?a ?t)
(arith_addf ?x (arith_addf ?y ?z ?a ?t) ?a ?t)
:ruleset rules
)
(rewrite ; (x * y) * z = x * (y * z)
(arith_mulf (arith_mulf ?x ?y ?a ?t) ?z ?a ?t)
(arith_mulf ?x (arith_mulf ?y ?z ?a ?t) ?a ?t)
:ruleset rules
)
; identity
(rewrite (arith_mulf ?x (arith_constant (NamedAttr "value" (FloatAttr 1.0 ?t)) ?t) ?a ?t) ?x :ruleset rules) ; x * 1 = x
(rewrite ; x^0 = 1
(math_powf ?x (arith_constant (NamedAttr "value" (FloatAttr 0.0 ?t)) ?t) ?a ?t)
(arith_constant (NamedAttr "value" (FloatAttr 1.0 ?t)) ?t)
:ruleset rules
)
(rule ; x^n = x * x^(n - 1)
((= ?lhs (math_powf ?x (arith_constant (NamedAttr "value" (FloatAttr ?n ?t)) ?t) ?a ?t))
(>= ?n 1.0))
((union
?lhs
(arith_mulf ?x (math_powf ?x (arith_constant (NamedAttr "value" (FloatAttr (- ?n 1.0) ?t)) ?t) ?a ?t) ?a ?t)
))
:ruleset rules
)
; mx + nx = x(m + n)
(rewrite
(arith_addf (arith_mulf ?m ?x ?a ?t) (arith_mulf ?n ?x ?a ?t) ?a ?t)
(arith_mulf ?x (arith_addf ?m ?n ?a ?t) ?a ?t)
:ruleset rules
)
(run-schedule (saturate rules)) ; search 0.017s, apply 0.002s, rebuild 0.006s, total 0.025s
;; EXTRACTS HERE ;;
(extract $op0)
(extract $op1)
(extract $op6)
(extract $op7)
(extract $op8)
(extract $op9)
(extract $op10)
(extract $op17)
(sort IntVec (Vec i64))
(sort FloatVec (Vec f64))
;; Types
(sort Type)
(sort TypeVec (Vec Type))
;; Attrs
(sort Attr)
(sort AttrDict (Map String Attr))
(sort AttrVec (Vec Attr))
(datatype AttrPair (NamedAttr String Attr) (ValueAttr Attr))
;; Op
;; Usage:
;; (<op_variant> <operand1> <operand2> ... <operandN> <attr1> <attr2> ... <attrM> <region1> <region2> ... <regionR> <type>)
(datatype Op
(Value i64 Type)
(OpaqueOp i64 TypeVec)
(NoOp)
)
(sort OpVec (Vec Op))
(datatype Block (Blk OpVec))
(sort BlockVec (Vec Block))
(datatype Region (Reg BlockVec))
(sort RegionVec (Vec Region))
;; helper functions
(function type-of (Op) Type :merge old)
(function dims (Type) IntVec :merge old)
;;;; builtin dialect ;;;;
;; Types
(constructor F16 () Type)
(constructor F32 () Type)
(constructor F64 () Type)
(constructor F80 () Type)
(constructor F128 () Type)
(constructor I1 () Type)
(constructor I4 () Type)
(constructor I8 () Type)
(constructor I16 () Type)
(constructor I32 () Type)
(constructor I64 () Type)
(constructor Int (i64) Type)
(constructor SInt (i64) Type)
(constructor UInt (i64) Type)
(constructor OtherInt (String) Type)
(constructor Index () Type)
(constructor None () Type)
(constructor Complex (Type) Type)
(constructor Tuple (TypeVec) Type)
(constructor Function (TypeVec TypeVec) Type)
(constructor Vector (IntVec Type) Type)
(constructor RankedTensor (IntVec Type) Type)
(constructor UnrankedTensor (Type) Type)
(constructor OpaqueType (String String) Type)
; Dynamic RankedTensor type
; (datatype Dimension
; (Dyn)
; (D i64)
; )
; (sort DimVec (Vec Dimension))
; (function DynRankedTensor (DimVec Type) Type)
; (rule ((= ?t (RankedTensor ?dims ?tp))) ((set (dims ?t) ?dims)))
;; Attrs
(constructor NoAttr () Attr)
(constructor IntegerAttr (i64 Type) Attr)
(constructor FloatAttr (f64 Type) Attr)
(constructor StringAttr (String) Attr)
(constructor UnitAttr () Attr)
(constructor TypeAttr (Type) Attr)
(constructor ArrayAttr (AttrVec) Attr)
(constructor DenseIntArrayAttr (i64 IntVec Type) Attr)
(constructor DenseFloatArrayAttr (f64 FloatVec Type) Attr)
(constructor DenseIntElementsAttr (FloatVec Type) Attr)
(constructor DenseFPElementsAttr (FloatVec Type) Attr)
(constructor SymbolRefAttr (String) Attr)
(constructor OpaqueAttr (String String) Attr) ; (<attr> <type-name>)
; DenseResourceElementsAttr
; DenseStringElementsAttr
; DictionaryAttr
; IntegerSetAttr
; OpaqueAttr
; SparseElementsAttr
; SymbolRefAttr
; StridedLayoutAttr
;;;; arith dialect ;;;;
;; Attrs
(datatype FastMathFlags (none) (reassoc) (nnan) (fast))
(constructor arith_fastmath (FastMathFlags) Attr)
;; Ops
(constructor arith_constant (AttrPair Type) Op)
(constructor arith_divf (Op Op AttrPair Type) Op)
;;;; math dialect ;;;;
(constructor math_sqrt (Op AttrPair Type) Op)
;;;; func dialect ;;;;
(constructor func_call (Op AttrPair Type) Op)
;; OPS HERE ;;
; fillRandomF64Tensor2D_func.func
(let $op0 (Value 0 (RankedTensor (vec-of -9223372036854775808 -9223372036854775808) (F64))))
(let $op1 (arith_constant (NamedAttr "value" (IntegerAttr 0 (I32))) (I32)))
(let $op2 (arith_constant (NamedAttr "value" (FloatAttr -10.0 (F64))) (F64)))
(let $op3 (arith_constant (NamedAttr "value" (FloatAttr 10.0 (F64))) (F64)))
(let $op4 (Value 4 (RankedTensor (vec-of -9223372036854775808 -9223372036854775808) (F64))))
(let $op5 (Value 5 (None)))
;; RULES HERE ;;
(ruleset rules)
(rewrite
(arith_divf
(arith_constant (NamedAttr "value" (FloatAttr 1.0 (F32))) (F32)) ; 1.0
(math_sqrt ?x (NamedAttr "fastmath" (arith_fastmath (fast))) (F32)) ; sqrt(x) with fastmath<fast>
(NamedAttr "fastmath" (arith_fastmath (fast))) (F32)) ; 1 / sqrt(x) with fastmath<fast>
(func_call ?x (NamedAttr "callee" (SymbolRefAttr "fast_inv_sqrt")) (F32))
:ruleset rules
)
(run-schedule (saturate rules))
;; EXTRACTS HERE ;;
(extract $op1)
(extract $op2)
(extract $op3)
(sort IntVec (Vec i64))
(sort FloatVec (Vec f64))
;; Types
(sort Type)
(sort TypeVec (Vec Type))
;; Attrs
(sort Attr)
(sort AttrDict (Map String Attr))
(sort AttrVec (Vec Attr))
(datatype AttrPair (NamedAttr String Attr) (ValueAttr Attr))
;; Op
;; Usage:
;; (<op_variant> <operand1> <operand2> ... <operandN> <attr1> <attr2> ... <attrM> <region1> <region2> ... <regionR> <type>)
(datatype Op
(Value i64 Type)
(OpaqueOp i64 TypeVec)
(NoOp)
)
(sort OpVec (Vec Op))
(datatype Block (Blk OpVec))
(sort BlockVec (Vec Block))
(datatype Region (Reg BlockVec))
(sort RegionVec (Vec Region))
;; helper functions
(function type-of (Op) Type :merge old)
(function dims (Type) IntVec :merge old)
;;;; builtin dialect ;;;;
;; Types
(constructor F16 () Type)
(constructor F32 () Type)
(constructor F64 () Type)
(constructor F80 () Type)
(constructor F128 () Type)
(constructor I1 () Type)
(constructor I4 () Type)
(constructor I8 () Type)
(constructor I16 () Type)
(constructor I32 () Type)
(constructor I64 () Type)
(constructor Int (i64) Type)
(constructor SInt (i64) Type)
(constructor UInt (i64) Type)
(constructor OtherInt (String) Type)
(constructor Index () Type)
(constructor None () Type)
(constructor Complex (Type) Type)
(constructor Tuple (TypeVec) Type)
(constructor Function (TypeVec TypeVec) Type)
(constructor Vector (IntVec Type) Type)
(constructor RankedTensor (IntVec Type) Type)
(constructor UnrankedTensor (Type) Type)
(constructor OpaqueType (String String) Type)
; Dynamic RankedTensor type
; (datatype Dimension
; (Dyn)
; (D i64)
; )
; (sort DimVec (Vec Dimension))
; (function DynRankedTensor (DimVec Type) Type)
; (rule ((= ?t (RankedTensor ?dims ?tp))) ((set (dims ?t) ?dims)))
;; Attrs
(constructor NoAttr () Attr)
(constructor IntegerAttr (i64 Type) Attr)
(constructor FloatAttr (f64 Type) Attr)
(constructor StringAttr (String) Attr)
(constructor UnitAttr () Attr)
(constructor TypeAttr (Type) Attr)
(constructor ArrayAttr (AttrVec) Attr)
(constructor DenseIntArrayAttr (i64 IntVec Type) Attr)
(constructor DenseFloatArrayAttr (f64 FloatVec Type) Attr)
(constructor DenseIntElementsAttr (FloatVec Type) Attr)
(constructor DenseFPElementsAttr (FloatVec Type) Attr)
(constructor SymbolRefAttr (String) Attr)
(constructor OpaqueAttr (String String) Attr) ; (<attr> <type-name>)
; DenseResourceElementsAttr
; DenseStringElementsAttr
; DictionaryAttr
; IntegerSetAttr
; OpaqueAttr
; SparseElementsAttr
; SymbolRefAttr
; StridedLayoutAttr
;;;; arith dialect ;;;;
;; Attrs
(datatype FastMathFlags (none) (reassoc) (nnan) (fast))
(constructor arith_fastmath (FastMathFlags) Attr)
;; Ops
(constructor arith_constant (AttrPair Type) Op)
(constructor arith_divf (Op Op AttrPair Type) Op)
;;;; math dialect ;;;;
(constructor math_sqrt (Op AttrPair Type) Op)
;;;; func dialect ;;;;
(constructor func_call (Op AttrPair Type) Op)
;; OPS HERE ;;
; normalize_distance_vectors_func.func
(let $op0 (Value 0 (RankedTensor (vec-of 100000000 3) (F32))))
(let $op1 (arith_constant (NamedAttr "value" (IntegerAttr 0 (Index))) (Index)))
(let $op2 (arith_constant (NamedAttr "value" (IntegerAttr 1 (Index))) (Index)))
(let $op3 (arith_constant (NamedAttr "value" (IntegerAttr 2 (Index))) (Index)))
(let $op4 (arith_constant (NamedAttr "value" (IntegerAttr 100000000 (Index))) (Index)))
(let $op5 (Value 5 (RankedTensor (vec-of 100000000 3) (F32))))
(let $op6 (Value 6 (RankedTensor (vec-of 100000000 3) (F32))))
(let $op7 (Value 7 (None)))
;; RULES HERE ;;
(ruleset rules)
(rewrite
(arith_divf
(arith_constant (NamedAttr "value" (FloatAttr 1.0 (F32))) (F32)) ; 1.0
(math_sqrt ?x (NamedAttr "fastmath" (arith_fastmath (fast))) (F32)) ; sqrt(x) with fastmath<fast>
(NamedAttr "fastmath" (arith_fastmath (fast))) (F32)) ; 1 / sqrt(x) with fastmath<fast>
(func_call ?x (NamedAttr "callee" (SymbolRefAttr "fast_inv_sqrt")) (F32))
:ruleset rules
)
(run-schedule (saturate rules))
;; EXTRACTS HERE ;;
(extract $op1)
(extract $op2)
(extract $op3)
(extract $op4)
(sort IntVec (Vec i64))
(sort FloatVec (Vec f64))
;; Types
(sort Type)
(sort TypeVec (Vec Type))
;; Attrs
(sort Attr)
(sort AttrDict (Map String Attr))
(sort AttrVec (Vec Attr))
(datatype AttrPair (NamedAttr String Attr) (ValueAttr Attr))
;; Op
;; Usage:
;; (<op_variant> <operand1> <operand2> ... <operandN> <attr1> <attr2> ... <attrM> <region1> <region2> ... <regionR> <type>)
(datatype Op
(Value i64 Type)
(OpaqueOp i64 TypeVec)
(NoOp)
)
(sort OpVec (Vec Op))
(datatype Block (Blk OpVec))
(sort BlockVec (Vec Block))
(datatype Region (Reg BlockVec))
(sort RegionVec (Vec Region))
;; helper functions
(function type-of (Op) Type :merge old)
(function dims (Type) IntVec :merge old)
;;;; builtin dialect ;;;;
;; Types
(constructor F16 () Type)
(constructor F32 () Type)
(constructor F64 () Type)
(constructor F80 () Type)
(constructor F128 () Type)
(constructor I1 () Type)
(constructor I4 () Type)
(constructor I8 () Type)
(constructor I16 () Type)
(constructor I32 () Type)
(constructor I64 () Type)
(constructor Int (i64) Type)
(constructor SInt (i64) Type)
(constructor UInt (i64) Type)
(constructor OtherInt (String) Type)
(constructor Index () Type)
(constructor None () Type)
(constructor Complex (Type) Type)
(constructor Tuple (TypeVec) Type)
(constructor Function (TypeVec TypeVec) Type)
(constructor Vector (IntVec Type) Type)
(constructor RankedTensor (IntVec Type) Type)
(constructor UnrankedTensor (Type) Type)
(constructor OpaqueType (String String) Type)
; Dynamic RankedTensor type
; (datatype Dimension
; (Dyn)
; (D i64)
; )
; (sort DimVec (Vec Dimension))
; (function DynRankedTensor (DimVec Type) Type)
; (rule ((= ?t (RankedTensor ?dims ?tp))) ((set (dims ?t) ?dims)))
;; Attrs
(constructor NoAttr () Attr)
(constructor IntegerAttr (i64 Type) Attr)
(constructor FloatAttr (f64 Type) Attr)
(constructor StringAttr (String) Attr)
(constructor UnitAttr () Attr)
(constructor TypeAttr (Type) Attr)
(constructor ArrayAttr (AttrVec) Attr)
(constructor DenseIntArrayAttr (i64 IntVec Type) Attr)
(constructor DenseFloatArrayAttr (f64 FloatVec Type) Attr)
(constructor DenseIntElementsAttr (FloatVec Type) Attr)
(constructor DenseFPElementsAttr (FloatVec Type) Attr)
(constructor SymbolRefAttr (String) Attr)
(constructor OpaqueAttr (String String) Attr) ; (<attr> <type-name>)
; DenseResourceElementsAttr
; DenseStringElementsAttr
; DictionaryAttr
; IntegerSetAttr
; OpaqueAttr
; SparseElementsAttr
; SymbolRefAttr
; StridedLayoutAttr
;;;; arith dialect ;;;;
;; Attrs
(datatype FastMathFlags (none) (reassoc) (nnan) (fast))
(constructor arith_fastmath (FastMathFlags) Attr)
;; Ops
(constructor arith_constant (AttrPair Type) Op)
(constructor arith_divf (Op Op AttrPair Type) Op)
;;;; math dialect ;;;;
(constructor math_sqrt (Op AttrPair Type) Op)
;;;; func dialect ;;;;
(constructor func_call (Op AttrPair Type) Op)
;; OPS HERE ;;
; blackbox_func.func
(let $op0 (Value 0 (RankedTensor (vec-of 100000000 3) (F32))))
(let $op1 (Value 1 (None)))
;; RULES HERE ;;
(ruleset rules)
(rewrite
(arith_divf
(arith_constant (NamedAttr "value" (FloatAttr 1.0 (F32))) (F32)) ; 1.0
(math_sqrt ?x (NamedAttr "fastmath" (arith_fastmath (fast))) (F32)) ; sqrt(x) with fastmath<fast>
(NamedAttr "fastmath" (arith_fastmath (fast))) (F32)) ; 1 / sqrt(x) with fastmath<fast>
(func_call ?x (NamedAttr "callee" (SymbolRefAttr "fast_inv_sqrt")) (F32))
:ruleset rules
)
(run-schedule (saturate rules))
;; EXTRACTS HERE ;;
(sort IntVec (Vec i64))
(sort FloatVec (Vec f64))
;; Types
(sort Type)
(sort TypeVec (Vec Type))
;; Attrs
(sort Attr)
(sort AttrDict (Map String Attr))
(sort AttrVec (Vec Attr))
(datatype AttrPair (NamedAttr String Attr) (ValueAttr Attr))
;; Op
;; Usage:
;; (<op_variant> <operand1> <operand2> ... <operandN> <attr1> <attr2> ... <attrM> <region1> <region2> ... <regionR> <type>)
(datatype Op
(Value i64 Type)
(OpaqueOp i64 TypeVec)
(NoOp)
)
(sort OpVec (Vec Op))
(datatype Block (Blk OpVec))
(sort BlockVec (Vec Block))
(datatype Region (Reg BlockVec))
(sort RegionVec (Vec Region))
;; helper functions
(function type-of (Op) Type :merge old)
(function dims (Type) IntVec :merge old)
;;;; builtin dialect ;;;;
;; Types
(constructor F16 () Type)
(constructor F32 () Type)
(constructor F64 () Type)
(constructor F80 () Type)
(constructor F128 () Type)
(constructor I1 () Type)
(constructor I4 () Type)
(constructor I8 () Type)
(constructor I16 () Type)
(constructor I32 () Type)
(constructor I64 () Type)
(constructor Int (i64) Type)
(constructor SInt (i64) Type)
(constructor UInt (i64) Type)
(constructor OtherInt (String) Type)
(constructor Index () Type)
(constructor None () Type)
(constructor Complex (Type) Type)
(constructor Tuple (TypeVec) Type)
(constructor Function (TypeVec TypeVec) Type)
(constructor Vector (IntVec Type) Type)
(constructor RankedTensor (IntVec Type) Type)
(constructor UnrankedTensor (Type) Type)
(constructor OpaqueType (String String) Type)
; Dynamic RankedTensor type
; (datatype Dimension
; (Dyn)
; (D i64)
; )
; (sort DimVec (Vec Dimension))
; (function DynRankedTensor (DimVec Type) Type)
; (rule ((= ?t (RankedTensor ?dims ?tp))) ((set (dims ?t) ?dims)))
;; Attrs
(constructor NoAttr () Attr)
(constructor IntegerAttr (i64 Type) Attr)
(constructor FloatAttr (f64 Type) Attr)
(constructor StringAttr (String) Attr)
(constructor UnitAttr () Attr)
(constructor TypeAttr (Type) Attr)
(constructor ArrayAttr (AttrVec) Attr)
(constructor DenseIntArrayAttr (i64 IntVec Type) Attr)
(constructor DenseFloatArrayAttr (f64 FloatVec Type) Attr)
(constructor DenseIntElementsAttr (FloatVec Type) Attr)
(constructor DenseFPElementsAttr (FloatVec Type) Attr)
(constructor SymbolRefAttr (String) Attr)
(constructor OpaqueAttr (String String) Attr) ; (<attr> <type-name>)
; DenseResourceElementsAttr
; DenseStringElementsAttr
; DictionaryAttr
; IntegerSetAttr
; OpaqueAttr
; SparseElementsAttr
; SymbolRefAttr
; StridedLayoutAttr
;;;; arith dialect ;;;;
;; Attrs
(datatype FastMathFlags (none) (reassoc) (nnan) (fast))
(constructor arith_fastmath (FastMathFlags) Attr)
;; Ops
(constructor arith_constant (AttrPair Type) Op)
(constructor arith_divf (Op Op AttrPair Type) Op)
;;;; math dialect ;;;;
(constructor math_sqrt (Op AttrPair Type) Op)
;;;; func dialect ;;;;
(constructor func_call (Op AttrPair Type) Op)
;; OPS HERE ;;
; main_func.func
(let $op0 (arith_constant (NamedAttr "value" (IntegerAttr 100000000 (Index))) (Index)))
(let $op1 (arith_constant (NamedAttr "value" (IntegerAttr 3 (Index))) (Index)))
(let $op2 (Value 2 (RankedTensor (vec-of -9223372036854775808 -9223372036854775808) (F64))))
(let $op3 (func_call $op2 (NamedAttr "callee" (SymbolRefAttr "fillRandomF64Tensor2D")) (RankedTensor (vec-of -9223372036854775808 -9223372036854775808) (F64))))
(let $op4 (Value 4 (RankedTensor (vec-of -9223372036854775808 -9223372036854775808) (F32))))
(let $op5 (Value 5 (RankedTensor (vec-of 100000000 3) (F32))))
(let $op6 (Value 6 (I64)))
(let $op7 (func_call $op5 (NamedAttr "callee" (SymbolRefAttr "normalize_distance_vectors")) (RankedTensor (vec-of 100000000 3) (F32))))
(let $op8 (Value 8 (I64)))
(let $op9 (func_call $op7 (NamedAttr "callee" (SymbolRefAttr "blackbox")) (RankedTensor (vec-of 100000000 3) (F32))))
(let $op10 (Value 10 (None)))
(let $op11 (Value 11 (None)))
(let $op12 (arith_constant (NamedAttr "value" (IntegerAttr 0 (I32))) (I32)))
(let $op13 (Value 13 (None)))
;; RULES HERE ;;
(ruleset rules)
(rewrite
(arith_divf
(arith_constant (NamedAttr "value" (FloatAttr 1.0 (F32))) (F32)) ; 1.0
(math_sqrt ?x (NamedAttr "fastmath" (arith_fastmath (fast))) (F32)) ; sqrt(x) with fastmath<fast>
(NamedAttr "fastmath" (arith_fastmath (fast))) (F32)) ; 1 / sqrt(x) with fastmath<fast>
(func_call ?x (NamedAttr "callee" (SymbolRefAttr "fast_inv_sqrt")) (F32))
:ruleset rules
)
(run-schedule (saturate rules))
;; EXTRACTS HERE ;;
(extract $op0)
(extract $op1)
(extract $op3)
(extract $op9)
(extract $op12)
(sort IntVec (Vec i64))
(sort FloatVec (Vec f64))
;; Types
(sort Type)
(sort TypeVec (Vec Type))
;; Attrs
(sort Attr)
(sort AttrDict (Map String Attr))
(sort AttrVec (Vec Attr))
(datatype AttrPair (NamedAttr String Attr) (ValueAttr Attr))
;; Op
;; Usage:
;; (<op_variant> <operand1> <operand2> ... <operandN> <attr1> <attr2> ... <attrM> <region1> <region2> ... <regionR> <type>)
(datatype Op
(Value i64 Type)
(OpaqueOp i64 TypeVec)
(NoOp)
)
(sort OpVec (Vec Op))
(datatype Block (Blk OpVec))
(sort BlockVec (Vec Block))
(datatype Region (Reg BlockVec))
(sort RegionVec (Vec Region))
;; helper functions
(function type-of (Op) Type :merge old)
(function dims (Type) IntVec :merge old)
;;;; builtin dialect ;;;;
;; Types
(constructor F16 () Type)
(constructor F32 () Type)
(constructor F64 () Type)
(constructor F80 () Type)
(constructor F128 () Type)
(constructor I1 () Type)
(constructor I4 () Type)
(constructor I8 () Type)
(constructor I16 () Type)
(constructor I32 () Type)
(constructor I64 () Type)
(constructor Int (i64) Type)
(constructor SInt (i64) Type)
(constructor UInt (i64) Type)
(constructor OtherInt (String) Type)
(constructor Index () Type)
(constructor None () Type)
(constructor Complex (Type) Type)
(constructor Tuple (TypeVec) Type)
(constructor Function (TypeVec TypeVec) Type)
(constructor Vector (IntVec Type) Type)
(constructor RankedTensor (IntVec Type) Type)
(constructor UnrankedTensor (Type) Type)
(constructor OpaqueType (String String) Type)
; Dynamic RankedTensor type
; (datatype Dimension
; (Dyn)
; (D i64)
; )
; (sort DimVec (Vec Dimension))
; (function DynRankedTensor (DimVec Type) Type)
; (rule ((= ?t (RankedTensor ?dims ?tp))) ((set (dims ?t) ?dims)))
;; Attrs
(constructor NoAttr () Attr)
(constructor IntegerAttr (i64 Type) Attr)
(constructor FloatAttr (f64 Type) Attr)
(constructor StringAttr (String) Attr)
(constructor UnitAttr () Attr)
(constructor TypeAttr (Type) Attr)
(constructor ArrayAttr (AttrVec) Attr)
(constructor DenseIntArrayAttr (i64 IntVec Type) Attr)
(constructor DenseFloatArrayAttr (f64 FloatVec Type) Attr)
(constructor DenseIntElementsAttr (FloatVec Type) Attr)
(constructor DenseFPElementsAttr (FloatVec Type) Attr)
(constructor SymbolRefAttr (String) Attr)
(constructor OpaqueAttr (String String) Attr) ; (<attr> <type-name>)
; DenseResourceElementsAttr
; DenseStringElementsAttr
; DictionaryAttr
; IntegerSetAttr
; OpaqueAttr
; SparseElementsAttr
; SymbolRefAttr
; StridedLayoutAttr
;;;; arith dialect ;;;;
;; Attrs
(datatype FastMathFlags (none) (reassoc) (nnan) (fast))
(constructor arith_fastmath (FastMathFlags) Attr)
;; Ops
(constructor arith_constant (AttrPair Type) Op)
(constructor arith_divf (Op Op AttrPair Type) Op)
;;;; math dialect ;;;;
(constructor math_sqrt (Op AttrPair Type) Op)
;;;; func dialect ;;;;
(constructor func_call (Op AttrPair Type) Op)
;; OPS HERE ;;
; fast_inv_sqrt_func.func
(let $op0 (Value 0 (F32)))
(let $op1 (arith_constant (NamedAttr "value" (IntegerAttr 1 (I32))) (I32)))
(let $op2 (arith_constant (NamedAttr "value" (FloatAttr 0.5 (F32))) (F32)))
(let $op3 (arith_constant (NamedAttr "value" (FloatAttr 1.5 (F32))) (F32)))
(let $op4 (arith_constant (NamedAttr "value" (IntegerAttr 1597463007 (I32))) (I32)))
(let $op5 (Value 5 (F32)))
(let $op6 (Value 6 (I32)))
(let $op7 (Value 7 (I32)))
(let $op8 (Value 8 (I32)))
(let $op9 (Value 9 (F32)))
(let $op10 (Value 10 (F32)))
(let $op11 (Value 11 (F32)))
(let $op12 (Value 12 (F32)))
(let $op13 (Value 13 (F32)))
(let $op14 (Value 14 (None)))
;; RULES HERE ;;
(ruleset rules)
(rewrite
(arith_divf
(arith_constant (NamedAttr "value" (FloatAttr 1.0 (F32))) (F32)) ; 1.0
(math_sqrt ?x (NamedAttr "fastmath" (arith_fastmath (fast))) (F32)) ; sqrt(x) with fastmath<fast>
(NamedAttr "fastmath" (arith_fastmath (fast))) (F32)) ; 1 / sqrt(x) with fastmath<fast>
(func_call ?x (NamedAttr "callee" (SymbolRefAttr "fast_inv_sqrt")) (F32))
:ruleset rules
)
(run-schedule (saturate rules))
;; EXTRACTS HERE ;;
(extract $op1)
(extract $op2)
(extract $op3)
(extract $op4)
func.func private @printNewline()
func.func private @clock() -> i64
func.func private @displayTime(i64, i64)
func.func private @printI64Tensor2D(tensor<?x?xi64>)
func.func @blackhole4k(%tensor: tensor<3840x2160x3xi64>) -> tensor<3840x2160x3xi64> {
func.return %tensor : tensor<3840x2160x3xi64>
}
func.func @blackhole4kgray(%tensor: tensor<3840x2160xi64>) -> tensor<3840x2160xi64> {
func.return %tensor : tensor<3840x2160xi64>
}
// 1 func, 7 arith, 5 tensor
func.func @main() -> i64 { // convert 4K RGB image to grayscale
%val = arith.constant 100 : i64
%image = tensor.empty() : tensor<3840x2160x3xi64> // 3840x2160 image with 3 channels (r, g, b)
%image_filled_ = linalg.fill ins(%val : i64) outs(%image : tensor<3840x2160x3xi64>) -> tensor<3840x2160x3xi64>
%image_filled = func.call @blackhole4k(%image_filled_) : (tensor<3840x2160x3xi64>) -> tensor<3840x2160x3xi64>
%start = func.call @clock() : () -> i64 // Start measuring time
%c0 = arith.constant 0 : index
%c1 = arith.constant 1 : index
%c2 = arith.constant 2 : index
%rows = arith.constant 3840 : index
%cols = arith.constant 2160 : index
%image_gray_init = tensor.empty() : tensor<3840x2160xi64>
%image_gray = scf.for %i = %c0 to %rows step %c1 iter_args(%current_image = %image_gray_init) -> (tensor<3840x2160xi64>) {
%row_result = scf.for %j = %c0 to %cols step %c1 iter_args(%current_row = %current_image) -> (tensor<3840x2160xi64>) {
%r = tensor.extract %image_filled[%i, %j, %c0] : tensor<3840x2160x3xi64>
%g = tensor.extract %image_filled[%i, %j, %c1] : tensor<3840x2160x3xi64>
%b = tensor.extract %image_filled[%i, %j, %c2] : tensor<3840x2160x3xi64>
%gray = func.call @rgb_to_grayscale(%r, %g, %b) : (i64, i64, i64) -> i64
%updated_row = tensor.insert %gray into %current_row[%i, %j] : tensor<3840x2160xi64>
scf.yield %updated_row : tensor<3840x2160xi64>
}
scf.yield %row_result : tensor<3840x2160xi64>
}
%end = func.call @clock() : () -> i64 // End measuring time
// %image_gray_cast = tensor.cast %image_gray : tensor<3840x2160xi64> to tensor<?x?xi64>
// func.call @printI64Tensor2D(%image_gray_cast) : (tensor<?x?xi64>) -> ()
func.call @blackhole4kgray(%image_gray) : (tensor<3840x2160xi64>) -> tensor<3840x2160xi64> // disable validation for speed
func.call @printNewline() : () -> ()
func.call @displayTime(%start, %end) : (i64, i64) -> ()
%c0_i64 = arith.constant 0 : i64
func.return %c0_i64 : i64
}
// 2 func, 12 arith
func.func @rgb_to_grayscale(%r: i64, %g: i64, %b: i64) -> i64 {
%c256 = arith.constant 256 : i64
// nums from https://www.baeldung.com/cs/convert-rgb-to-grayscale
%w_r = arith.constant 77 : i64
%w_g = arith.constant 150 : i64
%w_b = arith.constant 29 : i64
%r_s = arith.muli %r, %w_r : i64
%g_s = arith.muli %g, %w_g : i64
%b_s = arith.muli %b, %w_b : i64
%r_f = arith.divsi %r_s, %c256 : i64
%g_f = arith.divsi %g_s, %c256 : i64
%b_f = arith.divsi %b_s, %c256 : i64
// change above divisions to bitshifts
// %c8 = arith.constant 8 : i64
// %r_f = arith.shrsi %r_s, %c8 : i64
// %g_f = arith.shrsi %g_s, %c8 : i64
// %b_f = arith.shrsi %b_s, %c8 : i64
%sum = arith.addi %r_f, %g_f : i64
%gray = arith.addi %sum, %b_f : i64
func.return %gray : i64
}
Apache License
Version 2.0, January 2004
http://www.apache.org/licenses/
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
1. Definitions.
"License" shall mean the terms and conditions for use, reproduction,
and distribution as defined by Sections 1 through 9 of this document.
"Licensor" shall mean the copyright owner or entity authorized by
the copyright owner that is granting the License.
"Legal Entity" shall mean the union of the acting entity and all
other entities that control, are controlled by, or are under common
control with that entity. For the purposes of this definition,
"control" means (i) the power, direct or indirect, to cause the
direction or management of such entity, whether by contract or
otherwise, or (ii) ownership of fifty percent (50%) or more of the
outstanding shares, or (iii) beneficial ownership of such entity.
"You" (or "Your") shall mean an individual or Legal Entity
exercising permissions granted by this License.
"Source" form shall mean the preferred form for making modifications,
including but not limited to software source code, documentation
source, and configuration files.
"Object" form shall mean any form resulting from mechanical
transformation or translation of a Source form, including but
not limited to compiled object code, generated documentation,
and conversions to other media types.
"Work" shall mean the work of authorship, whether in Source or
Object form, made available under the License, as indicated by a
copyright notice that is included in or attached to the work
(an example is provided in the Appendix below).
"Derivative Works" shall mean any work, whether in Source or Object
form, that is based on (or derived from) the Work and for which the
editorial revisions, annotations, elaborations, or other modifications
represent, as a whole, an original work of authorship. For the purposes
of this License, Derivative Works shall not include works that remain
separable from, or merely link (or bind by name) to the interfaces of,
the Work and Derivative Works thereof.
"Contribution" shall mean any work of authorship, including
the original version of the Work and any modifications or additions
to that Work or Derivative Works thereof, that is intentionally
submitted to Licensor for inclusion in the Work by the copyright owner
or by an individual or Legal Entity authorized to submit on behalf of
the copyright owner. For the purposes of this definition, "submitted"
means any form of electronic, verbal, or written communication sent
to the Licensor or its representatives, including but not limited to
communication on electronic mailing lists, source code control systems,
and issue tracking systems that are managed by, or on behalf of, the
Licensor for the purpose of discussing and improving the Work, but
excluding communication that is conspicuously marked or otherwise
designated in writing by the copyright owner as "Not a Contribution."
"Contributor" shall mean Licensor and any individual or Legal Entity
on behalf of whom a Contribution has been received by Licensor and
subsequently incorporated within the Work.
2. Grant of Copyright License. Subject to the terms and conditions of
this License, each Contributor hereby grants to You a perpetual,
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
copyright license to reproduce, prepare Derivative Works of,
publicly display, publicly perform, sublicense, and distribute the
Work and such Derivative Works in Source or Object form.
3. Grant of Patent License. Subject to the terms and conditions of
this License, each Contributor hereby grants to You a perpetual,
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
(except as stated in this section) patent license to make, have made,
use, offer to sell, sell, import, and otherwise transfer the Work,
where such license applies only to those patent claims licensable
by such Contributor that are necessarily infringed by their
Contribution(s) alone or by combination of their Contribution(s)
with the Work to which such Contribution(s) was submitted. If You
institute patent litigation against any entity (including a
cross-claim or counterclaim in a lawsuit) alleging that the Work
or a Contribution incorporated within the Work constitutes direct
or contributory patent infringement, then any patent licenses
granted to You under this License for that Work shall terminate
as of the date such litigation is filed.
4. Redistribution. You may reproduce and distribute copies of the
Work or Derivative Works thereof in any medium, with or without
modifications, and in Source or Object form, provided that You
meet the following conditions:
(a) You must give any other recipients of the Work or
Derivative Works a copy of this License; and
(b) You must cause any modified files to carry prominent notices
stating that You changed the files; and
(c) You must retain, in the Source form of any Derivative Works
that You distribute, all copyright, patent, trademark, and
attribution notices from the Source form of the Work,
excluding those notices that do not pertain to any part of
the Derivative Works; and
(d) If the Work includes a "NOTICE" text file as part of its
distribution, then any Derivative Works that You distribute must
include a readable copy of the attribution notices contained
within such NOTICE file, excluding those notices that do not
pertain to any part of the Derivative Works, in at least one
of the following places: within a NOTICE text file distributed
as part of the Derivative Works; within the Source form or
documentation, if provided along with the Derivative Works; or,
within a display generated by the Derivative Works, if and
wherever such third-party notices normally appear. The contents
of the NOTICE file are for informational purposes only and
do not modify the License. You may add Your own attribution
notices within Derivative Works that You distribute, alongside
or as an addendum to the NOTICE text from the Work, provided
that such additional attribution notices cannot be construed
as modifying the License.
You may add Your own copyright statement to Your modifications and
may provide additional or different license terms and conditions
for use, reproduction, or distribution of Your modifications, or
for any such Derivative Works as a whole, provided Your use,
reproduction, and distribution of the Work otherwise complies with
the conditions stated in this License.
5. Submission of Contributions. Unless You explicitly state otherwise,
any Contribution intentionally submitted for inclusion in the Work
by You to the Licensor shall be under the terms and conditions of
this License, without any additional terms or conditions.
Notwithstanding the above, nothing herein shall supersede or modify
the terms of any separate license agreement you may have executed
with Licensor regarding such Contributions.
6. Trademarks. This License does not grant permission to use the trade
names, trademarks, service marks, or product names of the Licensor,
except as required for reasonable and customary use in describing the
origin of the Work and reproducing the content of the NOTICE file.
7. Disclaimer of Warranty. Unless required by applicable law or
agreed to in writing, Licensor provides the Work (and each
Contributor provides its Contributions) on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
implied, including, without limitation, any warranties or conditions
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
PARTICULAR PURPOSE. You are solely responsible for determining the
appropriateness of using or redistributing the Work and assume any
risks associated with Your exercise of permissions under this License.
8. Limitation of Liability. In no event and under no legal theory,
whether in tort (including negligence), contract, or otherwise,
unless required by applicable law (such as deliberate and grossly
negligent acts) or agreed to in writing, shall any Contributor be
liable to You for damages, including any direct, indirect, special,
incidental, or consequential damages of any character arising as a
result of this License or out of the use or inability to use the
Work (including but not limited to damages for loss of goodwill,
work stoppage, computer failure or malfunction, or any and all
other commercial damages or losses), even if such Contributor
has been advised of the possibility of such damages.
9. Accepting Warranty or Additional Liability. While redistributing
the Work or Derivative Works thereof, You may choose to offer,
and charge a fee for, acceptance of support, warranty, indemnity,
or other liability obligations and/or rights consistent with this
License. However, in accepting such obligations, You may act only
on Your own behalf and on Your sole responsibility, not on behalf
of any other Contributor, and only if You agree to indemnify,
defend, and hold each Contributor harmless for any liability
incurred by, or claims asserted against, such Contributor by reason
of your accepting any such warranty or additional liability.
END OF TERMS AND CONDITIONS
APPENDIX: How to apply the Apache License to your work.
To apply the Apache License to your work, attach the following
boilerplate notice, with the fields enclosed by brackets "[]"
replaced with your own identifying information. (Don't include
the brackets!) The text should be enclosed in the appropriate
comment syntax for the file format. We also recommend that a
file or class name and description of purpose be included on the
same "printed page" as the copyright notice for easier
identification within third-party archives.
Copyright [yyyy] [name of copyright owner]
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
{
"upstream": "https://github.com/AzizZayed/dialegg-cgo-artifact/tree/4d0d522e98c15becdc5e7d711348cb0891ff0d44",
"source_revision": "4d0d522e98c15becdc5e7d711348cb0891ff0d44",
"selection": "All 11 current DialEgg normal-only catalog entries; already repaired 2mm/3mm calls excluded.",
"cases": [
{
"case": "dialegg-image_conversion",
"source_input": "bench/image_conversion/image_conversion.mlir",
"invocation_zero_based": 0,
"function": "blackhole4k_func.func",
"original": "original-dialegg-image_conversion-000.egg",
"replay": "dialegg-image_conversion-000-normal-only.egg",
"extract_roots": [],
"proof_blocker": "No derived work to prove: the exported seeds contain none of the operators matched by this call's rewrite rules; any available extracted results already exist before the schedule."
},
{
"case": "dialegg-image_conversion",
"source_input": "bench/image_conversion/image_conversion.mlir",
"invocation_zero_based": 1,
"function": "blackhole4kgray_func.func",
"original": "original-dialegg-image_conversion-001.egg",
"replay": "dialegg-image_conversion-001-normal-only.egg",
"extract_roots": [],
"proof_blocker": "No derived work to prove: the exported seeds contain none of the operators matched by this call's rewrite rules; any available extracted results already exist before the schedule."
},
{
"case": "dialegg-image_conversion",
"source_input": "bench/image_conversion/image_conversion.mlir",
"invocation_zero_based": 2,
"function": "main_func.func",
"original": "original-dialegg-image_conversion-002.egg",
"replay": "dialegg-image_conversion-002-normal-only.egg",
"extract_roots": [
"op0",
"op5",
"op6",
"op7",
"op8",
"op9",
"op16"
],
"proof_blocker": "No derived work to prove: the exported seeds contain none of the operators matched by this call's rewrite rules; any available extracted results already exist before the schedule."
},
{
"case": "dialegg-vector_norm",
"source_input": "bench/vector_norm/vector_norm.mlir",
"invocation_zero_based": 0,
"function": "fillRandomF64Tensor2D_func.func",
"original": "original-dialegg-vector_norm-000.egg",
"replay": "dialegg-vector_norm-000-normal-only.egg",
"extract_roots": [
"op1",
"op2",
"op3"
],
"proof_blocker": "No derived work to prove: the exported seeds contain none of the operators matched by this call's rewrite rules; any available extracted results already exist before the schedule."
},
{
"case": "dialegg-vector_norm",
"source_input": "bench/vector_norm/vector_norm.mlir",
"invocation_zero_based": 1,
"function": "normalize_distance_vectors_func.func",
"original": "original-dialegg-vector_norm-001.egg",
"replay": "dialegg-vector_norm-001-normal-only.egg",
"extract_roots": [
"op1",
"op2",
"op3",
"op4"
],
"proof_blocker": "No derived work to prove: the exported seeds contain none of the operators matched by this call's rewrite rules; any available extracted results already exist before the schedule."
},
{
"case": "dialegg-vector_norm",
"source_input": "bench/vector_norm/vector_norm.mlir",
"invocation_zero_based": 2,
"function": "blackbox_func.func",
"original": "original-dialegg-vector_norm-002.egg",
"replay": "dialegg-vector_norm-002-normal-only.egg",
"extract_roots": [],
"proof_blocker": "No derived work to prove: the exported seeds contain none of the operators matched by this call's rewrite rules; any available extracted results already exist before the schedule."
},
{
"case": "dialegg-vector_norm",
"source_input": "bench/vector_norm/vector_norm.mlir",
"invocation_zero_based": 3,
"function": "main_func.func",
"original": "original-dialegg-vector_norm-003.egg",
"replay": "dialegg-vector_norm-003-normal-only.egg",
"extract_roots": [
"op0",
"op1",
"op3",
"op9",
"op12"
],
"proof_blocker": "No derived work to prove: the exported seeds contain none of the operators matched by this call's rewrite rules; any available extracted results already exist before the schedule."
},
{
"case": "dialegg-vector_norm",
"source_input": "bench/vector_norm/vector_norm.mlir",
"invocation_zero_based": 4,
"function": "fast_inv_sqrt_func.func",
"original": "original-dialegg-vector_norm-004.egg",
"replay": "dialegg-vector_norm-004-normal-only.egg",
"extract_roots": [
"op1",
"op2",
"op3",
"op4"
],
"proof_blocker": "No derived work to prove: the exported seeds contain none of the operators matched by this call's rewrite rules; any available extracted results already exist before the schedule."
},
{
"case": "dialegg-polynomial",
"source_input": "bench/polynomial/polynomial.mlir",
"invocation_zero_based": 0,
"function": "fillRandomF64Tensor2D_func.func",
"original": "original-dialegg-polynomial-000.egg",
"replay": "dialegg-polynomial-000-normal-only.egg",
"extract_roots": [
"op1",
"op2",
"op3"
],
"proof_blocker": "No derived work to prove: the exported seeds contain none of the operators matched by this call's rewrite rules; any available extracted results already exist before the schedule."
},
{
"case": "dialegg-polynomial",
"source_input": "bench/polynomial/polynomial.mlir",
"invocation_zero_based": 1,
"function": "blackbox_func.func",
"original": "original-dialegg-polynomial-001.egg",
"replay": "dialegg-polynomial-001-normal-only.egg",
"extract_roots": [],
"proof_blocker": "No derived work to prove: the exported seeds contain none of the operators matched by this call's rewrite rules; any available extracted results already exist before the schedule."
},
{
"case": "dialegg-polynomial",
"source_input": "bench/polynomial/polynomial.mlir",
"invocation_zero_based": 2,
"function": "main_func.func",
"original": "original-dialegg-polynomial-002.egg",
"replay": "dialegg-polynomial-002-normal-only.egg",
"extract_roots": [
"op0",
"op1",
"op6",
"op7",
"op8",
"op9",
"op10",
"op17"
],
"proof_blocker": "No derived work to prove: the exported seeds contain none of the operators matched by this call's rewrite rules; any available extracted results already exist before the schedule."
}
],
"files": {
"LICENSE.txt": "564856bd56fcdcc2764b34addb666abebd3682143777a806aacbbd5f65b85ff8",
"dialegg-image_conversion-000-normal-only.egg": "b7ac426ab0f9b2de5fe411b3b3012cd13fda91662f2b8f6306770aa0da58496b",
"dialegg-image_conversion-001-normal-only.egg": "1e2cac7facb9b3402293a9c7733da468273962d282b8cae26a284cfb55036197",
"dialegg-image_conversion-002-normal-only.egg": "5e1861a2149ae1c5c616febd73b4283135ae47469d122299cae61a167fcaff13",
"dialegg-polynomial-000-normal-only.egg": "6890d99fff258e5e8306cb7b3fb50f0460375aed4fe1944f3ae105cd89ae5aff",
"dialegg-polynomial-001-normal-only.egg": "4fc6525852e55e6e6e0c79bd577904346a8c70112fdd981b5fd6c5f63817042d",
"dialegg-polynomial-002-normal-only.egg": "882c7c764b1909ed71d9df44da1ea6d71f6b191c37bbbd116f40a7d1a2c279cc",
"dialegg-vector_norm-000-normal-only.egg": "af7d249204fbe4b66d9f7093795a56bf35c3d6977ebf751116976f938991924f",
"dialegg-vector_norm-001-normal-only.egg": "564aa250f185eb6bffadf40d8878b3abaec408e8c02d8f126f57852561db2ca4",
"dialegg-vector_norm-002-normal-only.egg": "7846dbc7e56d3df55c3bb1b1ef80a7e9e35a68a177a8f2511058109d7c7e92f8",
"dialegg-vector_norm-003-normal-only.egg": "f0f7ce34cdd85759eac1885f761f5478c6a0019a6eed979751575cac84e02389",
"dialegg-vector_norm-004-normal-only.egg": "b252776d6525cd5a72bcfb8202b9acf484749523e3c5534844219c0f4ccbb4ae",
"image_conversion.mlir": "3f2d8767ea68fd8d7153e9fd9652c8ea2e790eceadf310c4af49067943572fec",
"original-base.egg": "69768076a70f83075cafd00aa053b227e257ecf88e5afaf368af44801fae2e5f",
"original-dialegg-image_conversion-000.egg": "8037b74c54bdc972ba92547874a5d5a2af31c1f684c0cc510ee84251abac724e",
"original-dialegg-image_conversion-001.egg": "a458eabf9b58fbd47a48b0b404e0d323f0c49c212645ff87275b155ff0b911f5",
"original-dialegg-image_conversion-002.egg": "ca8acf4851a580bdb57bdf9c98d129f34b31f80325e444b0ee0cb82ece0fdbe7",
"original-dialegg-polynomial-000.egg": "52d12297baf1077c316f39af382264b1e0271b65fd028e9ec968276104f24377",
"original-dialegg-polynomial-001.egg": "5eb3135256f2057e0695ea3292fbb84890e50b5be5dff856580b072dce055bdd",
"original-dialegg-polynomial-002.egg": "9f15c9c6e645195e061a3f4df1e21b8e6774044b595937677197397d7ff7d772",
"original-dialegg-vector_norm-000.egg": "45d558367bb5c900d2d471681a65ed3b76888a8ecdcaec39b40b2509871c6fc6",
"original-dialegg-vector_norm-001.egg": "57591a4beab1ee089fb8c3c0d117fadfda9c39631bb112f15647bde9895e439b",
"original-dialegg-vector_norm-002.egg": "307636ab5a1138539df1b74bf9d185b64ee0daea9c76ddd18688b114f470b5ac",
"original-dialegg-vector_norm-003.egg": "8ebe72e26e6a1576a9fa7ed87060319b5dd97b6f301a3b21889063826c767289",
"original-dialegg-vector_norm-004.egg": "bfa953b569fc0876de4cd2cb1bca96d4a8215d2640318e83bddd04c2bfbda715",
"polynomial.mlir": "b975239bf84cf68f4facd62dcc5954e28eab46f8862b4502f8ca10c863db48c0",
"vector_norm.mlir": "f1d12c474a285ff3246f219a490c34408fbf2ec40adbe99ee798ce2f1bf520a5"
}
}
(sort IntVec (Vec i64))
(sort FloatVec (Vec f64))
;; Types
(sort Type)
(sort TypeVec (Vec Type))
;; Attrs
(sort Attr)
(sort AttrDict (Map String Attr))
(sort AttrVec (Vec Attr))
(datatype AttrPair (NamedAttr String Attr) (ValueAttr Attr))
;; Op
;; Usage:
;; (<op_variant> <operand1> <operand2> ... <operandN> <attr1> <attr2> ... <attrM> <region1> <region2> ... <regionR> <type>)
(datatype Op
(Value i64 Type)
(OpaqueOp i64 TypeVec)
(NoOp)
)
(sort OpVec (Vec Op))
(datatype Block (Blk OpVec))
(sort BlockVec (Vec Block))
(datatype Region (Reg BlockVec))
(sort RegionVec (Vec Region))
;; helper functions
(function type-of (Op) Type)
(function dims (Type) IntVec)
;;;; builtin dialect ;;;;
;; Types
(function F16 () Type)
(function F32 () Type)
(function F64 () Type)
(function F80 () Type)
(function F128 () Type)
(function I1 () Type)
(function I4 () Type)
(function I8 () Type)
(function I16 () Type)
(function I32 () Type)
(function I64 () Type)
(function Int (i64) Type)
(function SInt (i64) Type)
(function UInt (i64) Type)
(function OtherInt (String) Type)
(function Index () Type)
(function None () Type)
(function Complex (Type) Type)
(function Tuple (TypeVec) Type)
(function Function (TypeVec TypeVec) Type)
(function Vector (IntVec Type) Type)
(function RankedTensor (IntVec Type) Type)
(function UnrankedTensor (Type) Type)
(function OpaqueType (String String) Type)
; Dynamic RankedTensor type
; (datatype Dimension
; (Dyn)
; (D i64)
; )
; (sort DimVec (Vec Dimension))
; (function DynRankedTensor (DimVec Type) Type)
; (rule ((= ?t (RankedTensor ?dims ?tp))) ((set (dims ?t) ?dims)))
;; Attrs
(function NoAttr () Attr)
(function IntegerAttr (i64 Type) Attr)
(function FloatAttr (f64 Type) Attr)
(function StringAttr (String) Attr)
(function UnitAttr () Attr)
(function TypeAttr (Type) Attr)
(function ArrayAttr (AttrVec) Attr)
(function DenseIntArrayAttr (i64 IntVec Type) Attr)
(function DenseFloatArrayAttr (f64 FloatVec Type) Attr)
(function DenseIntElementsAttr (FloatVec Type) Attr)
(function DenseFPElementsAttr (FloatVec Type) Attr)
(function SymbolRefAttr (String) Attr)
(function OpaqueAttr (String String) Attr) ; (<attr> <type-name>)
; DenseResourceElementsAttr
; DenseStringElementsAttr
; DictionaryAttr
; IntegerSetAttr
; OpaqueAttr
; SparseElementsAttr
; SymbolRefAttr
; StridedLayoutAttr
(include "src/base.egg")
;;;; arith dialect ;;;;
(function arith_constant (AttrPair Type) Op)
(function arith_divsi (Op Op Type) Op :cost 2)
(function arith_shrsi (Op Op Type) Op)
;; OPS HERE ;;
; blackhole4k_func.func
(let op0 (Value 0 (RankedTensor (vec-of 3840 2160 3) (I64))))
(let op1 (Value 1 (None)))
;; RULES HERE ;;
(ruleset rules)
(rule ; division by a power of 2 is equivalent to right shift
((= ?lhs (arith_divsi ?x (arith_constant (NamedAttr "value" (IntegerAttr ?n ?t)) ?t) ?t)) ; x / n
(= ?lgn (log2 ?n)) ; if n = 2^k, then k = log2(n)
(= ?n (<< 1 ?lgn))) ; check if n is a power of 2
((union ?lhs (arith_shrsi ?x (arith_constant (NamedAttr "value" (IntegerAttr ?lgn ?t)) ?t) ?t))) ; x / n = x >> lgn
:ruleset rules
)
(run-schedule (saturate rules))
;; EXTRACTS HERE ;;
(include "src/base.egg")
;;;; arith dialect ;;;;
(function arith_constant (AttrPair Type) Op)
(function arith_divsi (Op Op Type) Op :cost 2)
(function arith_shrsi (Op Op Type) Op)
;; OPS HERE ;;
; blackhole4kgray_func.func
(let op0 (Value 0 (RankedTensor (vec-of 3840 2160) (I64))))
(let op1 (Value 1 (None)))
;; RULES HERE ;;
(ruleset rules)
(rule ; division by a power of 2 is equivalent to right shift
((= ?lhs (arith_divsi ?x (arith_constant (NamedAttr "value" (IntegerAttr ?n ?t)) ?t) ?t)) ; x / n
(= ?lgn (log2 ?n)) ; if n = 2^k, then k = log2(n)
(= ?n (<< 1 ?lgn))) ; check if n is a power of 2
((union ?lhs (arith_shrsi ?x (arith_constant (NamedAttr "value" (IntegerAttr ?lgn ?t)) ?t) ?t))) ; x / n = x >> lgn
:ruleset rules
)
(run-schedule (saturate rules))
;; EXTRACTS HERE ;;
(include "src/base.egg")
;;;; arith dialect ;;;;
(function arith_constant (AttrPair Type) Op)
(function arith_divsi (Op Op Type) Op :cost 2)
(function arith_shrsi (Op Op Type) Op)
;; OPS HERE ;;
; main_func.func
(let op0 (arith_constant (NamedAttr "value" (IntegerAttr 100 (I64))) (I64)))
(let op1 (Value 1 (RankedTensor (vec-of 3840 2160 3) (I64))))
(let op2 (Value 2 (RankedTensor (vec-of 3840 2160 3) (I64))))
(let op3 (Value 3 (RankedTensor (vec-of 3840 2160 3) (I64))))
(let op4 (Value 4 (I64)))
(let op5 (arith_constant (NamedAttr "value" (IntegerAttr 0 (Index))) (Index)))
(let op6 (arith_constant (NamedAttr "value" (IntegerAttr 1 (Index))) (Index)))
(let op7 (arith_constant (NamedAttr "value" (IntegerAttr 2 (Index))) (Index)))
(let op8 (arith_constant (NamedAttr "value" (IntegerAttr 3840 (Index))) (Index)))
(let op9 (arith_constant (NamedAttr "value" (IntegerAttr 2160 (Index))) (Index)))
(let op10 (Value 10 (RankedTensor (vec-of 3840 2160) (I64))))
(let op11 (Value 11 (RankedTensor (vec-of 3840 2160) (I64))))
(let op12 (Value 12 (I64)))
(let op13 (Value 13 (RankedTensor (vec-of 3840 2160) (I64))))
(let op14 (Value 14 (None)))
(let op15 (Value 15 (None)))
(let op16 (arith_constant (NamedAttr "value" (IntegerAttr 0 (I64))) (I64)))
(let op17 (Value 17 (None)))
;; RULES HERE ;;
(ruleset rules)
(rule ; division by a power of 2 is equivalent to right shift
((= ?lhs (arith_divsi ?x (arith_constant (NamedAttr "value" (IntegerAttr ?n ?t)) ?t) ?t)) ; x / n
(= ?lgn (log2 ?n)) ; if n = 2^k, then k = log2(n)
(= ?n (<< 1 ?lgn))) ; check if n is a power of 2
((union ?lhs (arith_shrsi ?x (arith_constant (NamedAttr "value" (IntegerAttr ?lgn ?t)) ?t) ?t))) ; x / n = x >> lgn
:ruleset rules
)
(run-schedule (saturate rules))
;; EXTRACTS HERE ;;
(extract op0)
(extract op5)
(extract op6)
(extract op7)
(extract op8)
(extract op9)
(extract op16)
(include "src/base.egg")
;;;; arith dialect ;;;;
;; Attrs
(datatype FastMathFlags (none) (reassoc) (nnan) (fast))
(function arith_fastmath (FastMathFlags) Attr)
;; Ops
(function arith_constant (AttrPair Type) Op)
(function arith_mulf (Op Op AttrPair Type) Op :cost 100)
(function arith_addf (Op Op AttrPair Type) Op)
;;;; math dialect ;;;;
(function math_powf (Op Op AttrPair Type) Op :cost 100000)
;; OPS HERE ;;
; fillRandomF64Tensor2D_func.func
(let op0 (Value 0 (RankedTensor (vec-of -9223372036854775808 -9223372036854775808) (F64))))
(let op1 (arith_constant (NamedAttr "value" (IntegerAttr 0 (I32))) (I32)))
(let op2 (arith_constant (NamedAttr "value" (FloatAttr -10.0 (F64))) (F64)))
(let op3 (arith_constant (NamedAttr "value" (FloatAttr 10.0 (F64))) (F64)))
(let op4 (Value 4 (RankedTensor (vec-of -9223372036854775808 -9223372036854775808) (F64))))
(let op5 (Value 5 (None)))
;; RULES HERE ;;
(ruleset rules)
; commutative
(rewrite (arith_addf ?x ?y ?a ?t) (arith_addf ?y ?x ?a ?t) :ruleset rules) ; x + y = y + x
(rewrite (arith_mulf ?x ?y ?a ?t) (arith_mulf ?y ?x ?a ?t) :ruleset rules) ; x * y = y * x
; associative
(rewrite ; (x + y) + z = x + (y + z)
(arith_addf (arith_addf ?x ?y ?a ?t) ?z ?a ?t)
(arith_addf ?x (arith_addf ?y ?z ?a ?t) ?a ?t)
:ruleset rules
)
(rewrite ; (x * y) * z = x * (y * z)
(arith_mulf (arith_mulf ?x ?y ?a ?t) ?z ?a ?t)
(arith_mulf ?x (arith_mulf ?y ?z ?a ?t) ?a ?t)
:ruleset rules
)
; identity
(rewrite (arith_mulf ?x (arith_constant (NamedAttr "value" (FloatAttr 1.0 ?t)) ?t) ?a ?t) ?x :ruleset rules) ; x * 1 = x
(rewrite ; x^0 = 1
(math_powf ?x (arith_constant (NamedAttr "value" (FloatAttr 0.0 ?t)) ?t) ?a ?t)
(arith_constant (NamedAttr "value" (FloatAttr 1.0 ?t)) ?t)
:ruleset rules
)
(rule ; x^n = x * x^(n - 1)
((= ?lhs (math_powf ?x (arith_constant (NamedAttr "value" (FloatAttr ?n ?t)) ?t) ?a ?t))
(>= ?n 1.0))
((union
?lhs
(arith_mulf ?x (math_powf ?x (arith_constant (NamedAttr "value" (FloatAttr (- ?n 1.0) ?t)) ?t) ?a ?t) ?a ?t)
))
:ruleset rules
)
; mx + nx = x(m + n)
(rewrite
(arith_addf (arith_mulf ?m ?x ?a ?t) (arith_mulf ?n ?x ?a ?t) ?a ?t)
(arith_mulf ?x (arith_addf ?m ?n ?a ?t) ?a ?t)
:ruleset rules
)
(run-schedule (saturate rules)) ; search 0.017s, apply 0.002s, rebuild 0.006s, total 0.025s
;; EXTRACTS HERE ;;
(extract op1)
(extract op2)
(extract op3)
(include "src/base.egg")
;;;; arith dialect ;;;;
;; Attrs
(datatype FastMathFlags (none) (reassoc) (nnan) (fast))
(function arith_fastmath (FastMathFlags) Attr)
;; Ops
(function arith_constant (AttrPair Type) Op)
(function arith_mulf (Op Op AttrPair Type) Op :cost 100)
(function arith_addf (Op Op AttrPair Type) Op)
;;;; math dialect ;;;;
(function math_powf (Op Op AttrPair Type) Op :cost 100000)
;; OPS HERE ;;
; blackbox_func.func
(let op0 (Value 0 (RankedTensor (vec-of 100000000) (F64))))
(let op1 (Value 1 (None)))
;; RULES HERE ;;
(ruleset rules)
; commutative
(rewrite (arith_addf ?x ?y ?a ?t) (arith_addf ?y ?x ?a ?t) :ruleset rules) ; x + y = y + x
(rewrite (arith_mulf ?x ?y ?a ?t) (arith_mulf ?y ?x ?a ?t) :ruleset rules) ; x * y = y * x
; associative
(rewrite ; (x + y) + z = x + (y + z)
(arith_addf (arith_addf ?x ?y ?a ?t) ?z ?a ?t)
(arith_addf ?x (arith_addf ?y ?z ?a ?t) ?a ?t)
:ruleset rules
)
(rewrite ; (x * y) * z = x * (y * z)
(arith_mulf (arith_mulf ?x ?y ?a ?t) ?z ?a ?t)
(arith_mulf ?x (arith_mulf ?y ?z ?a ?t) ?a ?t)
:ruleset rules
)
; identity
(rewrite (arith_mulf ?x (arith_constant (NamedAttr "value" (FloatAttr 1.0 ?t)) ?t) ?a ?t) ?x :ruleset rules) ; x * 1 = x
(rewrite ; x^0 = 1
(math_powf ?x (arith_constant (NamedAttr "value" (FloatAttr 0.0 ?t)) ?t) ?a ?t)
(arith_constant (NamedAttr "value" (FloatAttr 1.0 ?t)) ?t)
:ruleset rules
)
(rule ; x^n = x * x^(n - 1)
((= ?lhs (math_powf ?x (arith_constant (NamedAttr "value" (FloatAttr ?n ?t)) ?t) ?a ?t))
(>= ?n 1.0))
((union
?lhs
(arith_mulf ?x (math_powf ?x (arith_constant (NamedAttr "value" (FloatAttr (- ?n 1.0) ?t)) ?t) ?a ?t) ?a ?t)
))
:ruleset rules
)
; mx + nx = x(m + n)
(rewrite
(arith_addf (arith_mulf ?m ?x ?a ?t) (arith_mulf ?n ?x ?a ?t) ?a ?t)
(arith_mulf ?x (arith_addf ?m ?n ?a ?t) ?a ?t)
:ruleset rules
)
(run-schedule (saturate rules)) ; search 0.017s, apply 0.002s, rebuild 0.006s, total 0.025s
;; EXTRACTS HERE ;;
(include "src/base.egg")
;;;; arith dialect ;;;;
;; Attrs
(datatype FastMathFlags (none) (reassoc) (nnan) (fast))
(function arith_fastmath (FastMathFlags) Attr)
;; Ops
(function arith_constant (AttrPair Type) Op)
(function arith_mulf (Op Op AttrPair Type) Op :cost 100)
(function arith_addf (Op Op AttrPair Type) Op)
;;;; math dialect ;;;;
(function math_powf (Op Op AttrPair Type) Op :cost 100000)
;; OPS HERE ;;
; main_func.func
(let op0 (arith_constant (NamedAttr "value" (IntegerAttr 100000000 (Index))) (Index)))
(let op1 (arith_constant (NamedAttr "value" (IntegerAttr 4 (Index))) (Index)))
(let op2 (Value 2 (RankedTensor (vec-of -9223372036854775808 -9223372036854775808) (F64))))
(let op3 (Value 3 (RankedTensor (vec-of -9223372036854775808 -9223372036854775808) (F64))))
(let op4 (Value 4 (RankedTensor (vec-of 100000000 4) (F64))))
(let op5 (Value 5 (I64)))
(let op6 (arith_constant (NamedAttr "value" (FloatAttr 5.0 (F64))) (F64)))
(let op7 (arith_constant (NamedAttr "value" (IntegerAttr 0 (Index))) (Index)))
(let op8 (arith_constant (NamedAttr "value" (IntegerAttr 1 (Index))) (Index)))
(let op9 (arith_constant (NamedAttr "value" (IntegerAttr 2 (Index))) (Index)))
(let op10 (arith_constant (NamedAttr "value" (IntegerAttr 3 (Index))) (Index)))
(let op11 (Value 11 (RankedTensor (vec-of 100000000) (F64))))
(let op12 (Value 12 (RankedTensor (vec-of 100000000) (F64))))
(let op13 (Value 13 (I64)))
(let op14 (Value 14 (RankedTensor (vec-of 100000000) (F64))))
(let op15 (Value 15 (None)))
(let op16 (Value 16 (None)))
(let op17 (arith_constant (NamedAttr "value" (IntegerAttr 0 (I32))) (I32)))
(let op18 (Value 18 (None)))
;; RULES HERE ;;
(ruleset rules)
; commutative
(rewrite (arith_addf ?x ?y ?a ?t) (arith_addf ?y ?x ?a ?t) :ruleset rules) ; x + y = y + x
(rewrite (arith_mulf ?x ?y ?a ?t) (arith_mulf ?y ?x ?a ?t) :ruleset rules) ; x * y = y * x
; associative
(rewrite ; (x + y) + z = x + (y + z)
(arith_addf (arith_addf ?x ?y ?a ?t) ?z ?a ?t)
(arith_addf ?x (arith_addf ?y ?z ?a ?t) ?a ?t)
:ruleset rules
)
(rewrite ; (x * y) * z = x * (y * z)
(arith_mulf (arith_mulf ?x ?y ?a ?t) ?z ?a ?t)
(arith_mulf ?x (arith_mulf ?y ?z ?a ?t) ?a ?t)
:ruleset rules
)
; identity
(rewrite (arith_mulf ?x (arith_constant (NamedAttr "value" (FloatAttr 1.0 ?t)) ?t) ?a ?t) ?x :ruleset rules) ; x * 1 = x
(rewrite ; x^0 = 1
(math_powf ?x (arith_constant (NamedAttr "value" (FloatAttr 0.0 ?t)) ?t) ?a ?t)
(arith_constant (NamedAttr "value" (FloatAttr 1.0 ?t)) ?t)
:ruleset rules
)
(rule ; x^n = x * x^(n - 1)
((= ?lhs (math_powf ?x (arith_constant (NamedAttr "value" (FloatAttr ?n ?t)) ?t) ?a ?t))
(>= ?n 1.0))
((union
?lhs
(arith_mulf ?x (math_powf ?x (arith_constant (NamedAttr "value" (FloatAttr (- ?n 1.0) ?t)) ?t) ?a ?t) ?a ?t)
))
:ruleset rules
)
; mx + nx = x(m + n)
(rewrite
(arith_addf (arith_mulf ?m ?x ?a ?t) (arith_mulf ?n ?x ?a ?t) ?a ?t)
(arith_mulf ?x (arith_addf ?m ?n ?a ?t) ?a ?t)
:ruleset rules
)
(run-schedule (saturate rules)) ; search 0.017s, apply 0.002s, rebuild 0.006s, total 0.025s
;; EXTRACTS HERE ;;
(extract op0)
(extract op1)
(extract op6)
(extract op7)
(extract op8)
(extract op9)
(extract op10)
(extract op17)
(include "src/base.egg")
;;;; arith dialect ;;;;
;; Attrs
(datatype FastMathFlags (none) (reassoc) (nnan) (fast))
(function arith_fastmath (FastMathFlags) Attr)
;; Ops
(function arith_constant (AttrPair Type) Op)
(function arith_divf (Op Op AttrPair Type) Op)
;;;; math dialect ;;;;
(function math_sqrt (Op AttrPair Type) Op)
;;;; func dialect ;;;;
(function func_call (Op AttrPair Type) Op)
;; OPS HERE ;;
; fillRandomF64Tensor2D_func.func
(let op0 (Value 0 (RankedTensor (vec-of -9223372036854775808 -9223372036854775808) (F64))))
(let op1 (arith_constant (NamedAttr "value" (IntegerAttr 0 (I32))) (I32)))
(let op2 (arith_constant (NamedAttr "value" (FloatAttr -10.0 (F64))) (F64)))
(let op3 (arith_constant (NamedAttr "value" (FloatAttr 10.0 (F64))) (F64)))
(let op4 (Value 4 (RankedTensor (vec-of -9223372036854775808 -9223372036854775808) (F64))))
(let op5 (Value 5 (None)))
;; RULES HERE ;;
(ruleset rules)
(rewrite
(arith_divf
(arith_constant (NamedAttr "value" (FloatAttr 1.0 (F32))) (F32)) ; 1.0
(math_sqrt ?x (NamedAttr "fastmath" (arith_fastmath (fast))) (F32)) ; sqrt(x) with fastmath<fast>
(NamedAttr "fastmath" (arith_fastmath (fast))) (F32)) ; 1 / sqrt(x) with fastmath<fast>
(func_call ?x (NamedAttr "callee" (SymbolRefAttr "fast_inv_sqrt")) (F32))
:ruleset rules
)
(run-schedule (saturate rules))
;; EXTRACTS HERE ;;
(extract op1)
(extract op2)
(extract op3)
(include "src/base.egg")
;;;; arith dialect ;;;;
;; Attrs
(datatype FastMathFlags (none) (reassoc) (nnan) (fast))
(function arith_fastmath (FastMathFlags) Attr)
;; Ops
(function arith_constant (AttrPair Type) Op)
(function arith_divf (Op Op AttrPair Type) Op)
;;;; math dialect ;;;;
(function math_sqrt (Op AttrPair Type) Op)
;;;; func dialect ;;;;
(function func_call (Op AttrPair Type) Op)
;; OPS HERE ;;
; normalize_distance_vectors_func.func
(let op0 (Value 0 (RankedTensor (vec-of 100000000 3) (F32))))
(let op1 (arith_constant (NamedAttr "value" (IntegerAttr 0 (Index))) (Index)))
(let op2 (arith_constant (NamedAttr "value" (IntegerAttr 1 (Index))) (Index)))
(let op3 (arith_constant (NamedAttr "value" (IntegerAttr 2 (Index))) (Index)))
(let op4 (arith_constant (NamedAttr "value" (IntegerAttr 100000000 (Index))) (Index)))
(let op5 (Value 5 (RankedTensor (vec-of 100000000 3) (F32))))
(let op6 (Value 6 (RankedTensor (vec-of 100000000 3) (F32))))
(let op7 (Value 7 (None)))
;; RULES HERE ;;
(ruleset rules)
(rewrite
(arith_divf
(arith_constant (NamedAttr "value" (FloatAttr 1.0 (F32))) (F32)) ; 1.0
(math_sqrt ?x (NamedAttr "fastmath" (arith_fastmath (fast))) (F32)) ; sqrt(x) with fastmath<fast>
(NamedAttr "fastmath" (arith_fastmath (fast))) (F32)) ; 1 / sqrt(x) with fastmath<fast>
(func_call ?x (NamedAttr "callee" (SymbolRefAttr "fast_inv_sqrt")) (F32))
:ruleset rules
)
(run-schedule (saturate rules))
;; EXTRACTS HERE ;;
(extract op1)
(extract op2)
(extract op3)
(extract op4)
(include "src/base.egg")
;;;; arith dialect ;;;;
;; Attrs
(datatype FastMathFlags (none) (reassoc) (nnan) (fast))
(function arith_fastmath (FastMathFlags) Attr)
;; Ops
(function arith_constant (AttrPair Type) Op)
(function arith_divf (Op Op AttrPair Type) Op)
;;;; math dialect ;;;;
(function math_sqrt (Op AttrPair Type) Op)
;;;; func dialect ;;;;
(function func_call (Op AttrPair Type) Op)
;; OPS HERE ;;
; blackbox_func.func
(let op0 (Value 0 (RankedTensor (vec-of 100000000 3) (F32))))
(let op1 (Value 1 (None)))
;; RULES HERE ;;
(ruleset rules)
(rewrite
(arith_divf
(arith_constant (NamedAttr "value" (FloatAttr 1.0 (F32))) (F32)) ; 1.0
(math_sqrt ?x (NamedAttr "fastmath" (arith_fastmath (fast))) (F32)) ; sqrt(x) with fastmath<fast>
(NamedAttr "fastmath" (arith_fastmath (fast))) (F32)) ; 1 / sqrt(x) with fastmath<fast>
(func_call ?x (NamedAttr "callee" (SymbolRefAttr "fast_inv_sqrt")) (F32))
:ruleset rules
)
(run-schedule (saturate rules))
;; EXTRACTS HERE ;;
(include "src/base.egg")
;;;; arith dialect ;;;;
;; Attrs
(datatype FastMathFlags (none) (reassoc) (nnan) (fast))
(function arith_fastmath (FastMathFlags) Attr)
;; Ops
(function arith_constant (AttrPair Type) Op)
(function arith_divf (Op Op AttrPair Type) Op)
;;;; math dialect ;;;;
(function math_sqrt (Op AttrPair Type) Op)
;;;; func dialect ;;;;
(function func_call (Op AttrPair Type) Op)
;; OPS HERE ;;
; main_func.func
(let op0 (arith_constant (NamedAttr "value" (IntegerAttr 100000000 (Index))) (Index)))
(let op1 (arith_constant (NamedAttr "value" (IntegerAttr 3 (Index))) (Index)))
(let op2 (Value 2 (RankedTensor (vec-of -9223372036854775808 -9223372036854775808) (F64))))
(let op3 (func_call op2 (NamedAttr "callee" (SymbolRefAttr "fillRandomF64Tensor2D")) (RankedTensor (vec-of -9223372036854775808 -9223372036854775808) (F64))))
(let op4 (Value 4 (RankedTensor (vec-of -9223372036854775808 -9223372036854775808) (F32))))
(let op5 (Value 5 (RankedTensor (vec-of 100000000 3) (F32))))
(let op6 (Value 6 (I64)))
(let op7 (func_call op5 (NamedAttr "callee" (SymbolRefAttr "normalize_distance_vectors")) (RankedTensor (vec-of 100000000 3) (F32))))
(let op8 (Value 8 (I64)))
(let op9 (func_call op7 (NamedAttr "callee" (SymbolRefAttr "blackbox")) (RankedTensor (vec-of 100000000 3) (F32))))
(let op10 (Value 10 (None)))
(let op11 (Value 11 (None)))
(let op12 (arith_constant (NamedAttr "value" (IntegerAttr 0 (I32))) (I32)))
(let op13 (Value 13 (None)))
;; RULES HERE ;;
(ruleset rules)
(rewrite
(arith_divf
(arith_constant (NamedAttr "value" (FloatAttr 1.0 (F32))) (F32)) ; 1.0
(math_sqrt ?x (NamedAttr "fastmath" (arith_fastmath (fast))) (F32)) ; sqrt(x) with fastmath<fast>
(NamedAttr "fastmath" (arith_fastmath (fast))) (F32)) ; 1 / sqrt(x) with fastmath<fast>
(func_call ?x (NamedAttr "callee" (SymbolRefAttr "fast_inv_sqrt")) (F32))
:ruleset rules
)
(run-schedule (saturate rules))
;; EXTRACTS HERE ;;
(extract op0)
(extract op1)
(extract op3)
(extract op9)
(extract op12)
(include "src/base.egg")
;;;; arith dialect ;;;;
;; Attrs
(datatype FastMathFlags (none) (reassoc) (nnan) (fast))
(function arith_fastmath (FastMathFlags) Attr)
;; Ops
(function arith_constant (AttrPair Type) Op)
(function arith_divf (Op Op AttrPair Type) Op)
;;;; math dialect ;;;;
(function math_sqrt (Op AttrPair Type) Op)
;;;; func dialect ;;;;
(function func_call (Op AttrPair Type) Op)
;; OPS HERE ;;
; fast_inv_sqrt_func.func
(let op0 (Value 0 (F32)))
(let op1 (arith_constant (NamedAttr "value" (IntegerAttr 1 (I32))) (I32)))
(let op2 (arith_constant (NamedAttr "value" (FloatAttr 0.5 (F32))) (F32)))
(let op3 (arith_constant (NamedAttr "value" (FloatAttr 1.5 (F32))) (F32)))
(let op4 (arith_constant (NamedAttr "value" (IntegerAttr 1597463007 (I32))) (I32)))
(let op5 (Value 5 (F32)))
(let op6 (Value 6 (I32)))
(let op7 (Value 7 (I32)))
(let op8 (Value 8 (I32)))
(let op9 (Value 9 (F32)))
(let op10 (Value 10 (F32)))
(let op11 (Value 11 (F32)))
(let op12 (Value 12 (F32)))
(let op13 (Value 13 (F32)))
(let op14 (Value 14 (None)))
;; RULES HERE ;;
(ruleset rules)
(rewrite
(arith_divf
(arith_constant (NamedAttr "value" (FloatAttr 1.0 (F32))) (F32)) ; 1.0
(math_sqrt ?x (NamedAttr "fastmath" (arith_fastmath (fast))) (F32)) ; sqrt(x) with fastmath<fast>
(NamedAttr "fastmath" (arith_fastmath (fast))) (F32)) ; 1 / sqrt(x) with fastmath<fast>
(func_call ?x (NamedAttr "callee" (SymbolRefAttr "fast_inv_sqrt")) (F32))
:ruleset rules
)
(run-schedule (saturate rules))
;; EXTRACTS HERE ;;
(extract op1)
(extract op2)
(extract op3)
(extract op4)
func.func private @printNewline()
func.func private @clock() -> i64
func.func private @displayTime(i64, i64)
func.func private @printF64Tensor1D(tensor<?xf64>)
func.func @fillRandomF64Tensor2D(%tensor: tensor<?x?xf64>) -> tensor<?x?xf64> {
// Create a 2D tensor with random values with the linalg.fill_rng_2d op
%seed = arith.constant 0 : i32
%min = arith.constant -10.0 : f64
%max = arith.constant 10.0 : f64
%tensor_filled = linalg.fill_rng_2d ins(%min, %max, %seed : f64, f64, i32)
outs(%tensor : tensor<?x?xf64>) -> tensor<?x?xf64>
return %tensor_filled : tensor<?x?xf64>
}
func.func @blackbox(%t: tensor<100000000xf64>) -> tensor<100000000xf64> {
func.return %t : tensor<100000000xf64>
}
// 5 arith, 6 tensor, 2 scf, 1 func
func.func @main() -> i32 {
// polynomial a + bx + cx^2 + dx^3
%c100000000 = arith.constant 100000000 : index
%c4 = arith.constant 4 : index
%tensor_cast = tensor.empty(%c100000000, %c4) : tensor<?x?xf64>
%tensor_filled = func.call @fillRandomF64Tensor2D(%tensor_cast) : (tensor<?x?xf64>) -> tensor<?x?xf64>
%tensor = tensor.cast %tensor_filled : tensor<?x?xf64> to tensor<100000000x4xf64>
%start = func.call @clock() : () -> i64
%x = arith.constant 5.0 : f64
%c0 = arith.constant 0 : index
%c1 = arith.constant 1 : index
%c2 = arith.constant 2 : index
%c3 = arith.constant 3 : index
%poly_eval_init = tensor.empty() : tensor<100000000xf64>
%poly_eval = scf.for %i = %c0 to %c100000000 step %c1 iter_args(%current_poly_eval = %poly_eval_init) -> (tensor<100000000xf64>) {
%a = tensor.extract %tensor[%i, %c0] : tensor<100000000x4xf64>
%b = tensor.extract %tensor[%i, %c1] : tensor<100000000x4xf64>
%c = tensor.extract %tensor[%i, %c2] : tensor<100000000x4xf64>
%d = tensor.extract %tensor[%i, %c3] : tensor<100000000x4xf64>
%num = func.call @poly_eval_3(%a, %b, %c, %d, %x) : (f64, f64, f64, f64, f64) -> f64
%updated_poly_eval = tensor.insert %num into %current_poly_eval[%i] : tensor<100000000xf64>
scf.yield %updated_poly_eval : tensor<100000000xf64>
}
%end = func.call @clock() : () -> i64
// %poly_eval_cast = tensor.cast %poly_eval : tensor<100000000xf64> to tensor<?xf64>
// func.call @printF64Tensor1D(%poly_eval_cast) : (tensor<?xf64>) -> ()
func.call @blackbox(%poly_eval) : (tensor<100000000xf64>) -> tensor<100000000xf64> // disable validation for speed
func.call @printNewline() : () -> ()
func.call @displayTime(%start, %end) : (i64, i64) -> ()
%c0_i32 = arith.constant 0 : i32
func.return %c0_i32 : i32
}
// 2 func, 8 arith, 2 math
func.func @poly_eval_3(%a: f64, %b: f64, %c: f64, %d: f64, %x: f64) -> f64 {
%c2 = arith.constant 2.0 : f64
%c3 = arith.constant 3.0 : f64
%x_2 = math.powf %x, %c2 : f64 // x^2
%x_3 = math.powf %x, %c3 : f64 // x^3
%t1 = arith.mulf %c, %x : f64 // cx
%t2 = arith.mulf %b, %x_2 : f64 // bx^2
%t3 = arith.mulf %a, %x_3 : f64 // ax^3
%t4 = arith.addf %t2, %t3 : f64 // ax^3 + bx^2
%t5 = arith.addf %t1, %t4 : f64 // cx + ax^3 + bx^2
%t6 = arith.addf %d, %t5 : f64 // d + cx + ax^3 + bx^2
func.return %t6 : f64
}
func.func private @printNewline()
func.func private @clock() -> i64
func.func private @displayTime(i64, i64)
func.func private @printF32Tensor2D(tensor<?x?xf32>)
func.func @fillRandomF64Tensor2D(%tensor: tensor<?x?xf64>) -> tensor<?x?xf64> {
// Create a 2D tensor with random values with the linalg.fill_rng_2d op
%seed = arith.constant 0 : i32
%min = arith.constant -10.0 : f64
%max = arith.constant 10.0 : f64
%tensor_filled = linalg.fill_rng_2d ins(%min, %max, %seed : f64, f64, i32)
outs(%tensor : tensor<?x?xf64>) -> tensor<?x?xf64>
return %tensor_filled : tensor<?x?xf64>
}
// 3 func, 4 arith, 7 tensor, 2 scf
func.func @normalize_distance_vectors(%vectors: tensor<100000000x3xf32>) -> tensor<100000000x3xf32> {
// Distance between multiple 3D points and normalizing the resulting vectors. This is a common operation in computer graphics and physics simulations.
%c0 = arith.constant 0 : index
%c1 = arith.constant 1 : index
%c2 = arith.constant 2 : index
%c1000000 = arith.constant 100000000 : index
%norm_vectors_init = tensor.empty() : tensor<100000000x3xf32>
%norm_vectors = scf.for %i = %c0 to %c1000000 step %c1 iter_args(%current_vector = %norm_vectors_init) -> (tensor<100000000x3xf32>) {
%x = tensor.extract %vectors[%i, %c0] : tensor<100000000x3xf32>
%y = tensor.extract %vectors[%i, %c1] : tensor<100000000x3xf32>
%z = tensor.extract %vectors[%i, %c2] : tensor<100000000x3xf32>
%nx, %ny, %nz = func.call @normalize_vector(%x, %y, %z) : (f32, f32, f32) -> (f32, f32, f32)
%normalized_vector1 = tensor.insert %nx into %current_vector[%i, %c0] : tensor<100000000x3xf32>
%normalized_vector2 = tensor.insert %ny into %normalized_vector1[%i, %c1] : tensor<100000000x3xf32>
%normalized_vector3 = tensor.insert %nz into %normalized_vector2[%i, %c2] : tensor<100000000x3xf32>
scf.yield %normalized_vector3 : tensor<100000000x3xf32>
}
func.return %norm_vectors : tensor<100000000x3xf32>
}
func.func @blackbox(%t: tensor<100000000x3xf32>) -> tensor<100000000x3xf32> {
func.return %t : tensor<100000000x3xf32>
}
func.func @main() -> i32 {
%c1000000 = arith.constant 100000000 : index
%c3 = arith.constant 3 : index
%points_cast = tensor.empty(%c1000000, %c3) : tensor<?x?xf64>
%points_filled = func.call @fillRandomF64Tensor2D(%points_cast) : (tensor<?x?xf64>) -> tensor<?x?xf64>
%points_trunc = arith.truncf %points_filled : tensor<?x?xf64> to tensor<?x?xf32>
%points = tensor.cast %points_trunc : tensor<?x?xf32> to tensor<100000000x3xf32>
%start = func.call @clock() : () -> i64
%vectors_normalized = func.call @normalize_distance_vectors(%points) : (tensor<100000000x3xf32>) -> tensor<100000000x3xf32>
%end = func.call @clock() : () -> i64
// %vectors_normalized_cast = tensor.cast %vectors_normalized : tensor<100000000x3xf32> to tensor<?x?xf32>
// func.call @printF32Tensor2D(%vectors_normalized_cast) : (tensor<?x?xf32>) -> ()
func.call @blackbox(%vectors_normalized) : (tensor<100000000x3xf32>) -> tensor<100000000x3xf32> // disable validation for speed
func.call @printNewline() : () -> ()
func.call @displayTime(%start, %end) : (i64, i64) -> ()
%c0 = arith.constant 0 : i32
func.return %c0 : i32
}
// 2 func, 13 arith
func.func @fast_inv_sqrt(%x: f32) -> f32 {
// C code from https://en.wikipedia.org/wiki/Fast_inverse_square_root
// float Q_rsqrt(float number) {
// long i;
// float x2, y;
// const float threehalfs = 1.5F;
// x2 = number * 0.5F;
// y = number;
// i = * ( long * ) &y; // evil floating point bit level hacking
// i = 0x5f3759df - ( i >> 1 ); // what the fuck?
// y = * ( float * ) &i;
// y = y * ( threehalfs - ( x2 * y * y ) ); // 1st iteration
// // y = y * ( threehalfs - ( x2 * y * y ) ); // 2nd iteration, this can be removed
// return y;
// }
%c1 = arith.constant 1 : i32
%half = arith.constant 0.5 : f32
%three_halfs = arith.constant 1.5 : f32
%magic_number = arith.constant 0x5f3759df : i32
%x2 = arith.mulf %x, %half : f32 // x2 = number * 0.5F
%i = arith.bitcast %x : f32 to i32 // i = * ( long * ) &y
%i_shifted = arith.shrsi %i, %c1 : i32 // i >> 1
%i_subbed = arith.subi %magic_number, %i_shifted : i32 // i = 0x5f3759df - ( i >> 1 );
%y = arith.bitcast %i_subbed : i32 to f32 // y = * ( float * ) &i
%y2 = arith.mulf %y, %y : f32 // y2 = y * y
%x2y2 = arith.mulf %x2, %y2 : f32 // x2y2 = x2 * y * y
%sub = arith.subf %three_halfs, %x2y2 : f32 // sub = threehalfs - (x2 * y * y)
%y_it = arith.mulf %y, %sub : f32 // y_times_sub = y * (threehalfs - (x2 * y * y))
func.return %y_it : f32
}
// 2 func, 10 arith, 1 math
func.func @normalize_vector(%x: f32, %y: f32, %z: f32) -> (f32, f32, f32) {
%c1_f32 = arith.constant 1.0 : f32
%x_squared = arith.mulf %x, %x : f32
%y_squared = arith.mulf %y, %y : f32
%z_squared = arith.mulf %z, %z : f32
%distance_squared_1 = arith.addf %x_squared, %y_squared : f32
%distance_squared = arith.addf %distance_squared_1, %z_squared : f32 // distance_squared = x^2 + y^2 + z^2
%distance = math.sqrt %distance_squared fastmath<fast> : f32 // distance = sqrt(x^2 + y^2 + z^2)
%inv_distance = arith.divf %c1_f32, %distance fastmath<fast> : f32 // inv_distance = 1 / sqrt(x^2 + y^2 + z^2)
%x_normalized = arith.mulf %x, %inv_distance : f32
%y_normalized = arith.mulf %y, %inv_distance : f32
%z_normalized = arith.mulf %z, %inv_distance : f32
func.return %x_normalized, %y_normalized, %z_normalized : f32, f32, f32
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment