Skip to content

llvm.canonicalize() folding incorrect for denormals #59245

Description

@nunoplopes

File Transforms/InstSimplify/canonicalize.ll has the following test:

define float @canonicalize_neg_denorm_positive_zero_output_preserve_sign_input() "denormal-fp-math"="positive-zero,preserve-sign" {
; CHECK-LABEL: @canonicalize_neg_denorm_positive_zero_output_preserve_sign_input(
; CHECK-NEXT:    ret float 0.000000e+00
;
  %ret = call float @llvm.canonicalize.f32(float bitcast (i32 -2139095041 to float))
  ret float %ret
}

The expected result is wrong. This function should return -0.0.
If you run the equivalent multiplication by 1.0, you get -0.0:

define float @src() "denormal-fp-math"="positive-zero,preserve-sign" {
  %ret = fmul float bitcast (i32 -2139095041 to float), 1.0
  ret float %ret
}

define float @tgt() "denormal-fp-math"="positive-zero,preserve-sign" {
  ret float 0.0
}

Transformation doesn't verify!

ERROR: Value mismatch

Example:

Source:
float %ret = #x80000000 (-0.0)

Target:
Source value: #x80000000 (-0.0)
Target value: #x00000000 (+0.0)

In summary, canonicalize should use just the input denormal flag and ignore the output one.

cc @arsenm

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions