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

Sanjay Patel via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Mon Mar 21 09:15:22 PDT 2022


spatel added a comment.

In D122013#3396675 <https://reviews.llvm.org/D122013#3396675>, @bcl5980 wrote:

> 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

Sure - let's make one small change, and then I can commit for you.



================
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
----------------
bcl5980 wrote:
> 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 ]
> 
I see. It's fine to include a test with the 'add' from the motivating bug report, but the 'add' is not part of the minimal transform. We should remove it completely from at least these first 2 tests, so we can check that only this transform is tested.


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

https://reviews.llvm.org/D122013



More information about the llvm-commits mailing list