[PATCH] D122013: [InstCombine] Fold abs of known negative operand when source is sub

chenglin.bi via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Mon Mar 21 08:56:03 PDT 2022


bcl5980 added a comment.

In D122013#3396650 <https://reviews.llvm.org/D122013#3396650>, @spatel wrote:

> Do you have commit access? It would be good to push the original tests as a preliminary patch.

I have no commit access, can you help me to do this?
name: chenglin.bi
email: chenglin.bi at cixcomputing.com



================
Comment at: llvm/test/Transforms/InstCombine/abs-intrinsic.ll:473
+  %0 = call i32 @llvm.abs.i32(i32 %sub, i1 true)
+  %add = add nsw i32 %0, %x
+  br label %cond.end
----------------
spatel wrote:
> Why did the 'add' operand change from %y to %x?
when I change the condition code from sgt to slt, it become x < y
so abs(x - y) become y - x, I need to change the pattern to y - x + x then return only y
sub_abs_gt :
[ x>y ? abs (x-y) + y : 0 ] -> [ x > y ? x : 0 ]
sub_abs_lt :
[ x< y ? abs (x-y) + x : 0 ] -> [ x < y ? y : 0 ]



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

https://reviews.llvm.org/D122013



More information about the llvm-commits mailing list