Icing Supporting Fast-Math Style Optimizations in a Verified Compiler Heiko Becker , Eva Darulova, Magnus Myreen, Zachary Tatlock
How we develop programs readability over performance 2
How we develop programs readability over performance compiler should make program fast 2
How we develop programs readability over performance Compiler optimizations are compiler should make program fast a vital part of the development process 2
The need for understandable optimizations 3
The need for understandable optimizations 3
The need for understandable optimizations 3
The long road of compiler verification 1967: McCarthy, Painter ; Correctness of a Compiler for Arithmetic Expressions (Integer’s only) 2009: Leroy ; Formal Verification of a Realistic Compiler 2019: Lööw et al ; Verified Compilation on a Verified Processor 4
The long road of compiler verification 1967: McCarthy, Painter ; Correctness of a Compiler for Arithmetic Expressions (Integer’s only) 2009: Leroy ; CompCert C compiler Formal Verification of a Realistic Compiler 2019: Lööw et al ; Verified Compilation on a Verified Processor 4
The long road of compiler verification 1967: McCarthy, Painter ; Correctness of a Compiler for Arithmetic Expressions (Integer’s only) 2009: Leroy ; CompCert C compiler Formal Verification of a Realistic Compiler 2019: Lööw et al ; CakeML & Silver Verified Compilation on a Verified Processor 4
The long road of compiler verification 1967: McCarthy, Painter ; Correctness of a Compiler for Arithmetic Expressions (Integer’s only) 2009: Leroy ; Where are floating-points? Formal Verification of a Realistic Compiler 2019: Lööw et al ; Verified Compilation on a Verified Processor 4
The long road of compiler verification 1967: McCarthy, Painter ; Correctness of a Compiler for Arithmetic Expressions (Integer’s only) 2009: Leroy ; Formal Verification of a Realistic Compiler 2015: Boldo et al. ; Verified Compilation of Floating-Point Programs 2019: Lööw et al ; Verified Compilation on a Verified Processor 4
The state-of-the-art for fast-math Unverified Compilers (gcc, clang, ….) Verified Compilers (CakeML, ...) 5
The state-of-the-art for fast-math Unverified Compilers (gcc, clang, ….) Verified Compilers (CakeML, ...) • apply aggressive optimizations 5
The state-of-the-art for fast-math Unverified Compilers (gcc, clang, ….) Verified Compilers (CakeML, ...) • apply aggressive optimizations • do not preserve IEEE754 semantics 5
The state-of-the-art for fast-math Unverified Compilers (gcc, clang, ….) Verified Compilers (CakeML, ...) • apply aggressive optimizations • do not preserve IEEE754 semantics • give no guarantees on the result 5
The state-of-the-art for fast-math Unverified Compilers (gcc, clang, ….) Verified Compilers (CakeML, ...) • apply aggressive optimizations • apply no floating-point optimizations • do not preserve IEEE754 semantics • give no guarantees on the result 5
The state-of-the-art for fast-math Unverified Compilers (gcc, clang, ….) Verified Compilers (CakeML, ...) • apply aggressive optimizations • apply no floating-point optimizations • do not preserve IEEE754 semantics • fully preserve IEEE754 semantics • give no guarantees on the result 5
The state-of-the-art for fast-math Unverified Compilers (gcc, clang, ….) Verified Compilers (CakeML, ...) • apply aggressive optimizations • apply no floating-point optimizations • do not preserve IEEE754 semantics • fully preserve IEEE754 semantics • give no guarantees on the result • guarantee preserving literal meaning 5
The state-of-the-art for fast-math Unverified Compilers (gcc, clang, ….) Verified Compilers (CakeML, ...) • apply aggressive optimizations • apply no floating-point optimizations We need a semantics to • do not preserve IEEE754 semantics • fully preserve IEEE754 semantics handle fast-math optimizations • give no guarantees on the result • guarantee preserving literal meaning in verified compilers 5
Contributions Icing , a nondeterministic semantics for floating-points: • Support for subset of gcc’s fast-math optimizations • Optimization with fine-grained control • Implementation of three optimizers • Verification in HOL4 • Connection to CakeML 6
Optimizations in Icing Example Optimizations: Source Target 𝑏 + 𝑐 𝑐 + 𝑏 𝑐 × 𝑏 𝑏 × 𝑐 𝑏 + 𝑐 + 𝑑 𝑏 + (𝑐 + 𝑑) s t 𝑏 × 𝑐 × 𝑑 𝑏 × (𝑐 × 𝑑) 𝑏 × 𝑐 + 𝑑 𝐺𝑁𝐵(𝑏, 𝑐, 𝑑) 7
Optimizations in Icing Example Optimizations: Commutativity Source Target 𝑏 + 𝑐 𝑐 + 𝑏 (preserves IEEE754) 𝑐 × 𝑏 𝑏 × 𝑐 𝑏 + 𝑐 + 𝑑 𝑏 + (𝑐 + 𝑑) s t 𝑏 × 𝑐 × 𝑑 𝑏 × (𝑐 × 𝑑) 𝑏 × 𝑐 + 𝑑 𝐺𝑁𝐵(𝑏, 𝑐, 𝑑) 7
Optimizations in Icing Example Optimizations: Source Target 𝑏 + 𝑐 𝑐 + 𝑏 𝑐 × 𝑏 𝑏 × 𝑐 Associativity 𝑏 + 𝑐 + 𝑑 𝑏 + (𝑐 + 𝑑) (no IEEE754) s t 𝑏 × 𝑐 × 𝑑 𝑏 × (𝑐 × 𝑑) 𝑏 × 𝑐 + 𝑑 𝐺𝑁𝐵(𝑏, 𝑐, 𝑑) 7
Optimizations in Icing Example Optimizations: Source Target 𝑏 + 𝑐 𝑐 + 𝑏 𝑐 × 𝑏 𝑏 × 𝑐 𝑏 + 𝑐 + 𝑑 𝑏 + (𝑐 + 𝑑) s t 𝑏 × 𝑐 × 𝑑 𝑏 × (𝑐 × 𝑑) FMA introduction (locally more accurate) 𝑏 × 𝑐 + 𝑑 𝐺𝑁𝐵(𝑏, 𝑐, 𝑑) 7
Optimizations in Icing Example Optimizations: Source Target 𝑏 + 𝑐 𝑐 + 𝑏 𝑐 × 𝑏 𝑏 × 𝑐 𝑏 + 𝑐 + 𝑑 𝑏 + (𝑐 + 𝑑) s t 𝑏 × 𝑐 × 𝑑 𝑏 × (𝑐 × 𝑑) 𝑏 × 𝑐 + 𝑑 𝐺𝑁𝐵(𝑏, 𝑐, 𝑑) 7
Floating-Point Values in Icing IEEE754: Icing: 3.5 + 2.0 = 5.5 8
Floating-Point Values in Icing IEEE754: Icing: 3.5 + 2.0 = 5.5 floating-point word 8
Floating-Point Values in Icing IEEE754: Icing: 3.5 + 2.0 = 5.5 3.5 + 2.0 = floating-point word 8
Floating-Point Values in Icing IEEE754: Icing: + 3.5 + 2.0 = 5.5 3.5 + 2.0 = floating-point word 3.5 2.0 8
Floating-Point Values in Icing IEEE754: Icing: + 3.5 + 2.0 = 5.5 3.5 + 2.0 = floating-point word 3.5 2.0 value tree for addition 8
Floating-Point Values in Icing IEEE754: Icing: + 3.5 + 2.0 = 5.5 3.5 + 2.0 = floating-point word 3.5 2.0 value tree for addition 3.5 + (2.0 + 1.5) = 12.25 8
Floating-Point Values in Icing IEEE754: Icing: + 3.5 + 2.0 = 5.5 3.5 + 2.0 = floating-point word 3.5 2.0 value tree for addition 3.5 + (2.0 + 1.5) = 12.25 3.5 + (2.0 + 1.5) = 8
Floating-Point Values in Icing IEEE754: Icing: + 3.5 + 2.0 = 5.5 3.5 + 2.0 = floating-point word 3.5 2.0 value tree for addition + 3.5 + (2.0 + 1.5) = 12.25 3.5 + (2.0 + 1.5) = + 3.5 2.0 1. 5 8
Floating-Point Values in Icing IEEE754: Icing: + 3.5 + 2.0 = 5.5 3.5 + 2.0 = floating-point word 3.5 2.0 value tree for addition + 3.5 + (2.0 + 1.5) = 12.25 3.5 + (2.0 + 1.5) = + 3.5 2.0 1. 5 8
Icing’s semantics Allowed Optimization: 𝑏 × 𝑐 + 𝑑 𝐺𝑁𝐵(𝑏, 𝑐, 𝑑) 𝑐 × 𝑏 𝑏 × 𝑐 opt:(x * 2.4 + y) 9
Icing’s semantics Allowed Optimization: 𝑏 × 𝑐 + 𝑑 𝐺𝑁𝐵(𝑏, 𝑐, 𝑑) Included in the semantics 𝑐 × 𝑏 𝑏 × 𝑐 opt:(x * 2.4 + y) 9
Icing’s semantics Allowed Optimization: 𝑏 × 𝑐 + 𝑑 𝐺𝑁𝐵(𝑏, 𝑐, 𝑑) Included in the semantics 𝑐 × 𝑏 𝑏 × 𝑐 opt:(x * 2.4 + y) fine-grained control 9
Icing’s semantics Allowed Optimization: 𝑏 × 𝑐 + 𝑑 𝐺𝑁𝐵(𝑏, 𝑐, 𝑑) Included in the semantics 𝑐 × 𝑏 𝑏 × 𝑐 opt:(x * 2.4 + y) fine-grained control F𝑁𝐵 + + 𝑦 𝑧 𝑧 × 𝑧 × 2.4 2.4 𝑦 𝑦 2.4 9
Icing’s semantics Allowed Optimization: 𝑏 × 𝑐 + 𝑑 𝐺𝑁𝐵(𝑏, 𝑐, 𝑑) Included in the semantics 𝑐 × 𝑏 𝑏 × 𝑐 opt:(x * 2.4 + y) fine-grained control + F𝑁𝐵 + + 𝑦 𝑧 𝑧 𝑧 × × 𝑧 × 2.4 𝑦 2.4 2.4 𝑦 𝑦 2.4 9
Icing’s semantics Allowed Optimization: 𝑏 × 𝑐 + 𝑑 𝐺𝑁𝐵(𝑏, 𝑐, 𝑑) Included in the semantics 𝑐 × 𝑏 𝑏 × 𝑐 Icing: a direct fit for fast-math opt:(x * 2.4 + y) fine-grained control with fine-grained control and support for different optimizations + F𝑁𝐵 + + 𝑦 𝑧 𝑧 𝑧 × × 𝑧 × 2.4 𝑦 2.4 2.4 𝑦 𝑦 2.4 9
Modelling the state-of-the-art Unverified Compilers (gcc, clang, ….) Verified Compilers (CakeML, ...) • aggressive optimizations • no floating-point optimizations • no IEEE754 semantics • IEEE754 semantics • no guarantees on the result • introduces no new behaviour Icing provides: IEEE754 Translator greedy optimizer 10
Modelling the state-of-the-art Unverified Compilers (gcc, clang, ….) Verified Compilers (CakeML, ...) • aggressive optimizations • no floating-point optimizations • no IEEE754 semantics • IEEE754 semantics • no guarantees on the result • introduces no new behaviour Icing provides: greedy optimizer IEEE754 Translator 10
Recommend
More recommend