[FRONTEND][BACKEND] Lower tl.abs to math::Abs{I,F}Op (#1401)

This generates identical PTX for floating point, but for integer types
the resulting PTX is much better. For example `tl.abs` for int16
currently generates

```mlir
  cvt.s32.s16 %r1, %rs2;
  neg.s16     %rs4, %rs2;
  setp.lt.s32 %p4, %r1, 0;
  selp.b16    %rs3, %rs4, %rs2, %p4;
```

After, it becomes a single `abs.s16` instruction.

This also improves LLVM's ability to optimize floats. e.g. `abs(t) *
abs(t)` is optimized to `t * t` now which didn't happen before.

---------

Co-authored-by: Keren Zhou <kerenzhou@openai.com>
This commit is contained in:
peterbell10
2023-03-25 04:58:24 +00:00
committed by GitHub
parent a9c87245b4
commit 6063fccd0b
7 changed files with 102 additions and 13 deletions

View File

@@ -79,6 +79,7 @@ Math Ops
:toctree: generated
:nosignatures:
abs
exp
log
cos