[PATCH] D47041: [ValueTracking] Teach computeKnownBits that the result of an absolute value pattern that uses nsw flag is always positive.

Sanjay Patel via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Tue May 22 15:34:45 PDT 2018


spatel added inline comments.


================
Comment at: lib/Transforms/InstCombine/InstCombineAddSub.cpp:1636-1637
+        if (SPF == SPF_ABS || SPF == SPF_NABS) {
+          // This is a negate of an ABS/NABS pattern. Just swap the operands
+          // of the select.
+          SelectInst *SI = cast<SelectInst>(Op1);
----------------
We should copy and then swapProfMetadata for the new select rather than dropping that. Alternatively, we could swap the operands and metadata on the existing select and return it. Since we're checking hasOneUse(), I think it's ok to recycle.

This part can be a separate commit with independent tests like:

```
define i8 @negate_abs(i8 %x) {
  %n = sub i8 0, %x
  %c = icmp slt i8 %x, 0
  %s = select i1 %c, i8 %n, i8 %x
  %r = sub i8 0, %s
  ret i8 %r
}

define <2 x i8> @negate_nabs(<2 x i8> %x) {
  %n = sub <2 x i8> zeroinitializer, %x
  %c = icmp slt <2 x i8> %x, zeroinitializer
  %s = select <2 x i1> %c, <2 x i8> %x, <2 x i8> %n
  %r = sub <2 x i8> zeroinitializer, %s
  ret <2 x i8> %r
}

```


https://reviews.llvm.org/D47041





More information about the llvm-commits mailing list