Skip to Main content Skip to Navigation

Compiler optimisations and relaxed memory consistency models

Robin Morisset 1, 2
2 Parkas - Parallélisme de Kahn Synchrone
DI-ENS - Département d'informatique de l'École normale supérieure, CNRS - Centre National de la Recherche Scientifique, Inria de Paris
Abstract : Modern multiprocessors architectures and programming languages exhibit weakly consistent memories. Their behaviour is formalised by the memory model of the architecture or programming language; it precisely defines which write operation can be returned by each shared memory read. This is not always the latest store to the same variable, because of optimisations in the processors such as speculative execution of instructions, the complex effects of caches, and optimisations in the compilers. In this thesis we focus on the C11 memory model that is defined by the 2011 edition of the C standard. Our contributions are threefold. First, we focused on the theory surrounding the C11 model, formally studying which compiler optimisations it enables. We show that many common compiler optimisations are allowed, but, surprisingly, some important ones are forbidden. Secondly, building on our results, we developed a random testing methodology for detecting when mainstream compilers such as GCC or Clang perform an incorrect optimisation with respect to the memory model. We found several bugs in GCC, all promptly fixed. We also implemented a novel optimisation pass in LLVM, that looks for special instructions that restrict processor optimisations - called fence instructions - and eliminates the redundant ones. Finally, we developed a user-level scheduler for lightweight threads communicating through first-in first-out single-producer single-consumer queues. This programming model is known as Kahn process networks, and we show how to efficiently implement it, using C11 synchronisation primitives. This shows that despite its flaws, C11 can be usable in practice.
Document type :
Complete list of metadata

Cited literature [95 references]  Display  Hide  Download
Contributor : Abes Star :  Contact
Submitted on : Tuesday, June 26, 2018 - 10:19:05 AM
Last modification on : Thursday, July 1, 2021 - 5:58:09 PM
Long-term archiving on: : Wednesday, September 26, 2018 - 8:47:22 PM


Version validated by the jury (STAR)


  • HAL Id : tel-01823521, version 1



Robin Morisset. Compiler optimisations and relaxed memory consistency models. Other [cs.OH]. Université Paris sciences et lettres, 2017. English. ⟨NNT : 2017PSLEE050⟩. ⟨tel-01823521⟩



Record views


Files downloads