[PATCH] D48754: recognize more abs pattern

ChenZheng via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Thu Jun 28 22:39:51 PDT 2018


shchenz created this revision.
shchenz added reviewers: hfinkel, nemanjai, bogner, craig.topper, t.p.northover.
Herald added a reviewer: javed.absar.
Herald added a subscriber: hiraditya.

we should extend current combining select_cc procedure to recognize more abs pattern.
This patch handle two more pattern:
1:
define i64 @abs_expression64(i64 %a, i64 %b) {

  %1 = sub nsw i64 %a, %b
  %2 = icmp sgt i64 %1, 0
  %3 = sub nsw i64 %b, %a
  %4 = select i1 %2, i64 %1, i64 %3
  ret i64 %4

}
this should be |a-b|.

2:
define i64 @test2(i64 %a) {

  %tmp1neg = sub i64 0, %a
  %b = icmp sgt i64 %tmp1neg, -1

%abs = select i1 %b, i64 %tmp1neg, i64 %a

  ret i64 %abs

}
this should be |a|


https://reviews.llvm.org/D48754

Files:
  llvm/lib/CodeGen/SelectionDAG/DAGCombiner.cpp
  llvm/test/CodeGen/ARM/iabs.ll
  llvm/test/CodeGen/ARM/iabs64.ll
  llvm/test/CodeGen/PowerPC/iabs.ll
  llvm/test/CodeGen/PowerPC/iabs64.ll
  llvm/test/CodeGen/X86/iabs.ll

-------------- next part --------------
A non-text attachment was scrubbed...
Name: D48754.153437.patch
Type: text/x-patch
Size: 11109 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20180629/74668440/attachment.bin>


More information about the llvm-commits mailing list