This is an archive of the discontinued LLVM Phabricator instance.

DAG: Fix isKnownNeverNaN for basic non-sNaN cases
ClosedPublic

Authored by arsenm on Aug 15 2018, 1:34 PM.

Details

Summary

fadd/fsub/fmul need to worry about infinities as well as fdiv.

No test because the combines that care about the non-sNaN case are interfered with by matching compare and select patterns in the IR.

Diff Detail

Event Timeline

arsenm created this revision.Aug 15 2018, 1:34 PM

The change should be visible in tests because there's a DAGCombine that uses isKnownNeverNaN()?

Try the following with:
$ llc -o - fmaxnm.ll -mtriple=aarch64 -enable-no-signed-zeros-fp-math

; This should codegen to fmaxnm with no-signed-zeros.

define float @fmaxnm(i32 %i1, i32 %i2) {
  %f1 = uitofp i32 %i1 to float
  %fadd1 = fadd float %f1, 11.0
  %f2 = uitofp i32 %i2 to float
  %fadd2 = fadd float %f2, 17.0
  %cmp = fcmp uge float %fadd1, %fadd2
  %val = select i1 %cmp, float %fadd1, float %fadd2
  ret float %val
}

; If i1 is 0, fmul is NaN because 0.0 * -INF = NaN
; Therefore, this is not fmaxnm.

define float @not_fmaxnm(i32 %i1, i32 %i2) {
  %f1 = uitofp i32 %i1 to float
  %fmul = fmul float %f1, 0xfff0000000000000 ; -INFINITY as 64-bit hex
  %f2 = uitofp i32 %i2 to float
  %fadd2 = fadd float %f2, 17.0
  %cmp = fcmp uge float %fmul, %fadd2
  %val = select i1 %cmp, float %fmul, float %fadd2
  ret float %val
}
arsenm updated this revision to Diff 161264.Aug 17 2018, 8:34 AM

Add test

spatel accepted this revision.Aug 17 2018, 1:36 PM

LGTM

This revision is now accepted and ready to land.Aug 17 2018, 1:36 PM
arsenm closed this revision.Aug 17 2018, 2:20 PM

r340085