Wrong optimization: instability of x87 floating-point results leads to nonsense · Issue #44218 · llvm/llvm-project (original) (raw)

Bugzilla Link 44873
Version trunk
OS Linux
Reporter LLVM Bugzilla Contributor
CC @topperc,@LebedevRI,@RKSimon,@rotateright,@vinc17fr

Extended Description

x87 floating-point results are effectively unstable due to possible excess precision. Without extra care, this instability can taint everything around and lead to nonsense.

Instability is not limited to FP numbers, it extends to integers too:

#include <stdio.h>

attribute((noipa,optnone)) // imagine it in a separate TU static int opaque(int i) { return i; }

int main() { int z = opaque(1) + 0x1p-60 == 1;

printf("z = %d\n", z);
if (z) 
    puts("z is one");

}

$ clang -std=c11 -pedantic -Wall -Wextra -Wno-unknown-attributes -m32 -march=i686 -O3 test.c && ./a.out z = 0 z is one

----------------------------------------------------------------------
clang x86-64 version: clang version 11.0.0 (https://github.com/llvm/llvm-project 14ecbd7b8ded18af6c95f6a9957da541d1ec0e80)
----------------------------------------------------------------------