Issue 234374
Summary [InstCombine] Miscompilation where folding a negation into a division by a constant turns an exact division into a reciprocal multiply
Labels new issue
Assignees
Reporter sairam2661
    **Fuzzer Generated Test**

**Test Commit**
[e633c7da8ff144a11b3d875956fbaea06b969070](https://github.com/llvm/llvm-project/commit/e633c7da8ff144a11b3d875956fbaea06b969070)

**Description**
`foldFNegIntoConstant` rewrites `fneg arcp (fdiv X, C)` to `fdiv arcp X, -C`, taking `arcp` from the `fneg` alone, so the exact division becomes a multiply by a rounded reciprocal (related: #191653, #228557). Alive2 approximates `arcp`, so the output below also includes the run with `arcp` removed from both sides.

**Steps to reproduce**
- Minimized test case, `input.ll`

```llvm
define float @f(float %x) {
  %d = fdiv float %x, -42.0
  %r = fneg arcp float %d
  ret float %r
}
```

**Output**

```llvm

----------------------------------------
define float @f(float %x) {
#0:
  %d = fdiv float %x, -4.2e+01
  %r = fneg arcp float %d
  ret float %r
}
=>
define float @f(float %x) {
#0:
  %r = fmul arcp float %x, 2.3809524e-02
  ret float %r
}
ERROR: Couldn't prove the correctness of the transformation
Alive2 approximated the semantics of the programs and therefore we
cannot conclude whether the bug found is valid or not.

Approximations done:
 - arcp


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

----------------------------------------
define float @f(float %x) {
#0:
  %d = fdiv float %x, -4.2e+01
  %r = fneg float %d
  ret float %r
}
=>
define float @f(float %x) {
#0:
  %r = fmul float %x, 2.3809524e-02
  ret float %r
}
Transformation doesn't verify!

ERROR: Value mismatch

Example:
float %x = #x000000bd (2.65e-43)

Source:
float %d = #x80000004 (-6e-45)
float %r = #x00000004 (6e-45)

Target:
float %r = #x00000005 (7e-45)
Source value: #x00000004 (6e-45)
Target value: #x00000005 (7e-45)

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

**CC**: @regehr
_______________________________________________
llvm-bugs mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-bugs

Reply via email to