[llvm] [SROA] Propagate no-signed-zeros(nsz) fast-math flag on the phi node using function attribute (PR #83381)

Nuno Lopes via llvm-commits llvm-commits at lists.llvm.org
Sun Jul 7 08:20:46 PDT 2024


nunoplopes wrote:

Alive2 complains about this commit:
```llvm
define double @fabs_fcmp_olt_nsz_func_attr(double %#0, double %#1) {
entry:
  %x = alloca i64 8, align 8
  store double %#0, ptr %x, align 8
  %cmp = fcmp nnan nsz olt double %#0, 0.000000
  br i1 %cmp, label %if.then, label %return

if.then:
  %fneg = fneg nnan nsz double %#0
  store double %fneg, ptr %x, align 8
  br label %return

return:
  %ret = load double, ptr %x, align 8
  ret double %ret
}
=>
define double @fabs_fcmp_olt_nsz_func_attr(double %#0, double %#1) {
entry:
  %cmp = fcmp nnan nsz olt double %#0, 0.000000
  br i1 %cmp, label %if.then, label %return

if.then:
  %fneg = fneg nnan nsz double %#0
  br label %return

return:
  %x.0 = phi nsz double [ %fneg, %if.then ], [ %#0, %entry ]
  ret double %x.0
}
Transformation doesn't verify! (unsound)
ERROR: Target's return value is more undefined

Example:
double %#0 = #x0000000000000000 (+0.0)
double %#1 = poison

Source:
ptr %x = pointer(local, block_id=0, offset=0)
i1 %cmp = #x0 (0)
  >> Jump to %return
double %ret = #x0000000000000000 (+0.0)

Target:
i1 %cmp = #x0 (0)
  >> Jump to %return
double %x.0 = #x8000000000000000 (-0.0)
Source value: #x0000000000000000 (+0.0)
Target value: #x8000000000000000 (-0.0)
```

https://github.com/llvm/llvm-project/pull/83381


More information about the llvm-commits mailing list