llvm / llvm/llvm-project

[ConstantFolding] Miscompilation of constrained fsub

Open
#177,467 2 comments 0 reactions 0 assignees View on GitHub
floating-point generated by fuzzer llvm:optimizations miscompilation
Dominant language
LLVM
Stars
40.5k
Forks
18.7k
PR merge metrics
PR metrics pending

Description

**Fuzzer Generated Test**
**Reproducer**
https://alive2.llvm.org/ce/z/ti9u9X

**Description**
`fsub double 0.0, 0.0` with `rounding=dynamic, exceptions=strict` is incorrectly folded to `+0.0`

**Steps to reproduce**
- Minimized test case, `input.ll`
```
define double @test() {
%res = call double @llvm.experimental.constrained.fsub.f64(double 0.000000e+00, double 0.000000e+00, metadata !"round.dynamic", metadata !"fpexcept.strict")
ret double %res
}

; Function Attrs: nocallback nofree nosync nounwind strictfp willreturn memory(inaccessiblemem: readwrite)
declare double @llvm.experimental.constrained.fsub.f64(double, double, metadata, metadata) #0

attributes #0 = { nocallback nofree nosync nounwind strictfp willreturn memory(inaccessiblemem: readwrite) }
```

**Output**
```
----------------------------------------
define double @test() {
#0:
%res = fsub double 0.000000, 0.000000, rounding=dynamic, exceptions=strict
ret double %res
}
=>
define double @test() nofree noundef willreturn memory(none) {
#0:
ret double 0.000000
}
Transformation doesn't verify!

ERROR: Value mismatch

Example:

Source:
double %res = #x8000000000000000 (-0.0)

Target:
Source value: #x8000000000000000 (-0.0)
Target value: #x0000000000000000 (+0.0)

Summary:
0 correct transformations
1 incorrect transformations
0 failed-to-prove transformations
0 Alive2 errors
```

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.