[PATCH] D39766: [InstCombine] Teach visitICmpInst to not break integer absolute value idioms

Sanjay Patel via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Fri Nov 10 06:39:25 PST 2017


spatel added a comment.

Should we recognize (and canonicalize) this abs() pattern:

  define i64 @abs5(i64 %x) {
    %signbit = ashr i64 %x, 63      ; smear the sign bit
    %add = add i64 %x, %signbit     ; add 0 or -1
    %abs = xor i64 %add, %signbit   ; x < 0 ? -x : x
    ret i64 %abs
  }

(note: I mentioned this pattern to the group looking at matching vector idioms earlier this year - not sure what happened to that effort).

Independent of that, how about calling ValueTracking's matchSelectPattern()? Then, we could check all of min/max/abs in one shot without repeating the logic here.


https://reviews.llvm.org/D39766





More information about the llvm-commits mailing list