[PATCH] D127964: [DCE] Eliminate no-op atan and atan2 calls

Mohammed Nurul Hoque via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Tue Jul 19 03:55:31 PDT 2022


mohammed-nurulhoque added inline comments.


================
Comment at: llvm/test/Transforms/EarlyCSE/atan.ll:21
+entry:
+  %call = call float @atanf(float 0x7FF0000000000000)
+  ret float %call
----------------
sepavloff wrote:
> Why it is not constfolded? C11 (F.10.1.3) states:
> ```
> atan(±∞) returns ±π /2.
> ```
infinity and NaN are not folded because in `ConstantFoldScalarCall1` there's this snippet:
```  
    /// We only fold functions with finite arguments. Folding NaN and inf is
    /// likely to be aborted with an exception anyway, and some host libms
    /// have known errors raising exceptions.
    if (!U.isFinite())
      return nullptr;
```
This is too conservative as your example shows, but changing it will affect most of the floating point functions, so it's probably best left for a separate commit.
Interestingly, the same wasn't done for calls with 2 arguments as atan2 with Inf&NaN arguments are folded as the newly added test cases show.


================
Comment at: llvm/test/Transforms/EarlyCSE/atan.ll:49
+; CHECK-NEXT:  entry:
+; CHECK-NEXT:    [[CALL:%.*]] = call float @atan2f(float -0.000000e+00, float 0.000000e+00)
+; CHECK-NEXT:    ret float -0.000000e+00
----------------
sepavloff wrote:
> Why it is not removed? The value is not used and it should not have side effect, no?
It's removed indeed. I accidentally uploaded the wrong diff.


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D127964/new/

https://reviews.llvm.org/D127964



More information about the llvm-commits mailing list