This is an archive of the discontinued LLVM Phabricator instance.

[MLIR] add negi in standard dialect
AbandonedPublic

Authored by qqsun8819 on Mar 4 2020, 7:13 PM.

Details

Reviewers
None
Summary

Now we only have negf to accept float arguments. In llvm ir neg can also support integer arguments,
so add a negi in standard dialect so that neg can support integer arguments
This patch is inspired by lowering TF dialect to HLO dialect when a hlo.neg is created whose argument is integer, like:

%1 = "xla_hlo.neg"(%13) : (tensor<64>) -> tensor<i64>

Diff Detail

Event Timeline

qqsun8819 created this revision.Mar 4 2020, 7:13 PM
Herald added a project: Restricted Project. · View Herald TranscriptMar 4 2020, 7:13 PM

I understand that this is present in TF and HLO, but do we need this in standard right now? How do you plan to use this?
(It seems like this isn't an instruction in LLVM right now)

ftynse added a subscriber: ftynse.Mar 5 2020, 1:40 AM

I think integer negation is always okay being implemented as "0 - x" (the only dangerous case is signed INT_MIN, but negating it leads to overflow in any case). This isn't the case for floating point numbers because of special values (nan/inf) and normalization, so it needs an instruction.

I understand that this is present in TF and HLO, but do we need this in standard right now? How do you plan to use this?
(It seems like this isn't an instruction in LLVM right now)

I create a pr in TF to add use this instruction in lhlo lowering to linalg : https://github.com/tensorflow/tensorflow/pull/37381

ftynse added a comment.Mar 6 2020, 1:03 AM

I understand that this is present in TF and HLO, but do we need this in standard right now? How do you plan to use this?
(It seems like this isn't an instruction in LLVM right now)

I create a pr in TF to add use this instruction in lhlo lowering to linalg : https://github.com/tensorflow/tensorflow/pull/37381

And what prevents you from emitting

%0 = constant 0 : i??
%1 = cmpi "slt" %arg, %0 : i??
%2 = subi %0, %arg : i??
%3 = select %1, %2, %arg

there instead of changing the standard dialect?

flaub added a subscriber: flaub.Mar 6 2020, 11:47 AM
qqsun8819 abandoned this revision.Apr 11 2020, 9:15 PM

solved in https://github.com/tensorflow/tensorflow/pull/37381 no need to modify standard dialect