Skip to main content
QUICK REVIEW

[Paper Review] Challenges and Opportunities in C/C++ Source-To-Source Compilation (Invited Paper)

Bispo, João, Paulino, Nuno|arXiv (Cornell University)|Jan 1, 2023
Numerical Methods and AlgorithmsComputer Science22 references72 citations
TL;DR

This paper introduces Verificarlo, an LLVM-based compiler tool that enables automatic, transparent Monte Carlo Arithmetic (MCA) for C/C++/Fortran codes to assess floating-point accuracy. By instrumenting the LLVM intermediate representation, Verificarlo captures the impact of compiler optimizations on numerical stability and outperforms CADNA and CIL-based MCA in detecting numerical noise and providing reliable confidence intervals without source code modification.

ABSTRACT

The C/C++ compilation stack (Intermediate Representations (IR), compilation passes and backends) is encumbered by a steep learning curve, which we believe can be lowered by complementing it with approaches such as source-to-source compilation. Source-to-source compilation is a technology that is widely used and quite mature in certain programming environments, such as JavaScript, but that faces a low adoption rate in others. In the particular case of C and C++ some of the identified factors include the high complexity of the languages, increased difficulty in building and maintaining C/C++ parsers, or limitations on using source code as an intermediate representation. Additionally, new technologies such as Multi-Level Intermediate Representation (MLIR) have appeared as potential competitors to source-to-source compilers at this level. In this paper, we present what we have identified as current challenges of source-to-source compilation of C and C++, as well as what we consider to be opportunities and possible directions forward. We also present several examples, implemented on top of the Clava source-to-source compiler, that use some of these ideas and techniques to raise the abstraction level of compiler research on complex compiled languages such as C or C++. The examples include automatic parallelization of for loops, high-level synthesis optimisation, hardware/software partitioning with run-time decisions, and automatic insertion of inline assembly for fast prototyping of custom instructions.

Motivation & Objective

  • Address the critical need for automated, scalable numerical accuracy verification in scientific computing, especially for exascale and highly parallel workloads.
  • Overcome limitations of existing tools like CADNA and CIL, which require manual source code modifications or lack support for compiler optimization effects.
  • Provide a fully automatic, end-to-end solution for estimating confidence intervals on floating-point results using Monte Carlo Arithmetic at the intermediate representation level.
  • Enable accurate detection of numerical instability in large-scale scientific codes where traditional methods fail due to overestimation or lack of transparency.

Proposed method

  • Integrates Monte Carlo Arithmetic (MCA) into the LLVM compiler infrastructure at the intermediate representation (IR) level, enabling transparent instrumentation without source code changes.
  • Implements three MCA modes: Random Rounding (RR), Precision Bounding (PB), and Full MCA, which inject random perturbations into floating-point operations to simulate rounding errors.
  • Uses the inexact(x) = x + 2ex−tξ function to model virtual precision t, where ξ is a uniform random variable in (−0.5, 0.5), enabling unbiased error simulation.
  • Employs MPFR for high-precision arithmetic during MCA execution to ensure accurate statistical estimation of mean and standard deviation of results.
  • Computes significant digits using s′ = −logβ(σ / |μ|), where μ and σ are the sample mean and standard deviation over multiple MCA trials.
  • Supports all major scientific languages (C, C++, Fortran) via LLVM’s language-agnostic IR, enabling cross-optimization analysis.

Experimental results

Research questions

  • RQ1Can Monte Carlo Arithmetic be effectively and transparently applied at the LLVM intermediate representation level to assess floating-point accuracy without source code modification?
  • RQ2How does Verificarlo’s MCA-based approach compare to CADNA and CIL-based MCA in detecting numerical instability and estimating significant digits?
  • RQ3To what extent do compiler optimizations affect numerical accuracy, and can this be captured and quantified using a compiler-based MCA tool?
  • RQ4Can Verificarlo reliably detect cases where floating-point results are effectively numerical noise, such as in catastrophic cancellation or loss of significance?

Key findings

  • Verificarlo successfully detects that the alternating counter case study produces numerical noise with zero significant digits, correctly identifying the result as unreliable despite IEEE-754 returning non-zero values.
  • In the alternating counter case, Verificarlo reports a mean result of ¯c = −45.101042 with a standard deviation of σ(c) = 44.33 over 1000 samples, yielding s′ = 0 significant digits, indicating no reliable information.
  • CADNA overestimates the significant digits in the same case, reporting s = 3, and incorrectly estimates the mean as −0.103 × 10⁶, which is far from the true expected value of −50.
  • For the linear equation system, Verificarlo estimates 8.3 significant digits in single precision and 8.2 in double precision, closely matching the expected accuracy.
  • Verificarlo’s MCA results show a stable evolution of significant digits over iterations, while CADNA exhibits spurious and inconsistent estimates.
  • Verificarlo captures the impact of compiler optimizations on numerical accuracy—unlike source-to-source tools such as CIL—which is a key advantage for realistic HPC workloads.

Read this paper

Open the full text in the Nubint reader and ask about any passage as you read.

Read this paper on Nubint

This review was generated by AI from the original paper. Please check the paper before citing it.