]> granicus.if.org Git - llvm/commit
[CGP] eliminate a sub instruction in memcmp expansion
authorSanjay Patel <spatel@rotateright.com>
Tue, 27 Jun 2017 21:46:34 +0000 (21:46 +0000)
committerSanjay Patel <spatel@rotateright.com>
Tue, 27 Jun 2017 21:46:34 +0000 (21:46 +0000)
commitca9df19568d44e4a5058ce809bcea83e33476e3c
tree9b09e2d4e27f7e77b1114b020d50c9d0244407aa
parent96470fe7e99e340ff67454d98c32935a43e530c5
[CGP] eliminate a sub instruction in memcmp expansion

As noted in D34071, there are some IR optimization opportunities that could be
handled by normal IR passes if this expansion wasn't happening so late in CGP.

Regardless of that, it seems wasteful to knowingly produce suboptimal IR here,
so I'm proposing this change:
  %s = sub i32 %x, %y
  %r = icmp ne %s, 0
    =>
  %r = icmp ne %x, %y

Changing the predicate to 'eq' mimics what InstCombine would do, so that's just
an efficiency improvement if we decide this expansion should happen sooner.

The fact that the PowerPC backend doesn't eliminate the 'subf.' might be
something for PPC folks to investigate separately.

Differential Revision: https://reviews.llvm.org/D34416

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@306471 91177308-0d34-0410-b5e6-96231b3b80d8
lib/CodeGen/CodeGenPrepare.cpp
test/CodeGen/PowerPC/memCmpUsedInZeroEqualityComparison.ll
test/CodeGen/PowerPC/memcmp.ll
test/CodeGen/PowerPC/memcmpIR.ll
test/CodeGen/X86/memcmp.ll
test/Transforms/CodeGenPrepare/X86/memcmp.ll