[PATCH] D87197: [InstSimplify] Fold degenerate abs of abs form

Nikita Popov via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Sat Sep 5 15:27:48 PDT 2020


nikic added a comment.

In D87197#2257839 <https://reviews.llvm.org/D87197#2257839>, @efriedma wrote:

> It doesn't matter that the constant is 0 specifically, does it?  Should work for any constant besides INT_MIN with the correct sign.

I believe this is only valid for 0 specifically, because that's where abs(X) == -abs(X). (Well, and for INT_MIN in the non-poisoning case, as both abs and neg preserve it as well.)

> Is it worth trying to generalize this?  It seems like something along the lines of SimplifyWithOpReplaced should be able to simplify this.

Yes, conceptually this could be handled by SimplifyWithOpReplaced. However, it requires replacing operands two levels up (in an abs that is used by a neg that is used by the select). Given the still open correctness issues from https://bugs.llvm.org/show_bug.cgi?id=47322, it seems dangerous to try and generalize it further.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D87197



More information about the llvm-commits mailing list