This is an archive of the discontinued LLVM Phabricator instance.

[mlir][math] Add `math.absi` op
ClosedPublic

Authored by Mogball on Aug 6 2022, 9:12 AM.

Details

Summary

Adds an integer absolute value op to the math dialect.

When converting to LLVM, this op is lowered to the LLVM abs intrinsic.
When converting to SPIRV, this op is lowered to spv.GL.SAbs.

Depends on D131325

Diff Detail

Event Timeline

Mogball created this revision.Aug 6 2022, 9:12 AM
Mogball requested review of this revision.Aug 6 2022, 9:12 AM
ftynse accepted this revision.Aug 8 2022, 6:11 AM
This revision is now accepted and ready to land.Aug 8 2022, 6:11 AM
This revision was landed with ongoing or failed builds.Aug 8 2022, 8:05 AM
This revision was automatically updated to reflect the committed changes.
aartbik added inline comments.Aug 11 2022, 11:09 AM
mlir/test/Conversion/MathToLLVM/math-to-llvm.mlir
13

Did you test this end-to-end? The actual intrinsic takes an extra parameter

declare i32 @llvm.abs.i32(i32 <src>, i1 <is_int_min_poison>)

so I am not sure this will actually execute properly when using the execution engine on the resulting LLVM IR?

aartbik added inline comments.Aug 11 2022, 12:31 PM
mlir/test/Conversion/MathToLLVM/math-to-llvm.mlir
13

This end-to-end test cannot run yet due to this issue:

https://reviews.llvm.org/D131712

Mogball added inline comments.Aug 11 2022, 12:32 PM
mlir/test/Conversion/MathToLLVM/math-to-llvm.mlir
13

Good catch! Let me submit a fix.

aartbik added inline comments.Aug 11 2022, 12:33 PM
mlir/test/Conversion/MathToLLVM/math-to-llvm.mlir
13

Thanks!

Mogball marked 2 inline comments as done.Aug 12 2022, 8:34 AM
Mogball added inline comments.
mlir/test/Conversion/MathToLLVM/math-to-llvm.mlir
13