Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Incorrect swap of fptrunc with fast-math instructions #48424

Open
nunoplopes opened this issue Feb 7, 2021 · 1 comment
Open

Incorrect swap of fptrunc with fast-math instructions #48424

nunoplopes opened this issue Feb 7, 2021 · 1 comment
Labels
bugzilla Issues migrated from bugzilla floating-point Floating-point math llvm:instcombine miscompilation

Comments

@nunoplopes
Copy link
Member

nunoplopes commented Feb 7, 2021

Bugzilla Link 49080
Version trunk
OS All
CC @LebedevRI,@RKSimon,@arsenm,@regehr,@rotateright

Extended Description

See the example below where fptrunc & fabs are swapped. The issue is that fabs has the nninf tag, which becomes poison because its input is inf.

Two solutions come to mind: drop nninf from fabs in the solution, or add fast-math flags to fptrunc.

define half @test_shrink_intrin_fabs_fast_double_src(float %D) {
  %E = fabs fast float %D
  %F = fptrunc float %E to half
  ret half %F
}
=>
define half @test_shrink_intrin_fabs_fast_double_src(float %D) {
  %1 = fptrunc float %D to half
  %F = fabs fast half %1
  ret half %F
}
Transformation doesn't verify!
ERROR: Target is more poisonous than source

Example:
float %D = #x477ff080 (65520.5)

Source:
float %E = #x477ff080 (65520.5)
half %F = #x7c00 (+oo)

Target:
half %1 = #x7c00 (+oo)
half %F = poison
Source value: #x7c00 (+oo)
Target value: poison

File: llvm/test/Transforms/InstCombine/double-float-shrink-2.ll
A similar test also fails in Transforms/InstCombine/fpcast.ll (test4-fast)

@rotateright
Copy link
Contributor

The general direction is to allow FMF on any FP value, and we've seen real examples where it would make sense on FP casts.

So adding FMF to fptrunc/fpext is probably what we need to do first...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bugzilla Issues migrated from bugzilla floating-point Floating-point math llvm:instcombine miscompilation
Projects
None yet
Development

No branches or pull requests

3 participants