InstCombine: Turn (zext A) == (B & (1<<X)-1) into A == (trunc B), narrowing the compare.
authorBenjamin Kramer <benny.kra@googlemail.com>
Sun, 10 Jun 2012 20:35:00 +0000 (20:35 +0000)
committerBenjamin Kramer <benny.kra@googlemail.com>
Sun, 10 Jun 2012 20:35:00 +0000 (20:35 +0000)
commit66821d902040f838a97bf04a4b910fdc11ba49a9
tree4e71e22e3b9c24402a519c93918d9d17ff9ff548
parent71ffcfe9f8602785d4d9133e029c37f2fac78cc3
InstCombine: Turn (zext A) == (B & (1<<X)-1) into A == (trunc B), narrowing the compare.

This saves a cast, and zext is more expensive on platforms with subreg support
than trunc is. This occurs in the BSD implementation of memchr(3), see PR12750.
On the synthetic benchmark from that bug stupid_memchr and bsd_memchr have the
same performance now when not inlining either function.

stupid_memchr: 323.0us
bsd_memchr: 321.0us
memchr: 479.0us

where memchr is the llvm-gcc compiled bsd_memchr from osx lion's libc. When
inlining is enabled bsd_memchr still regresses down to llvm-gcc memchr time,
I haven't fully understood the issue yet, something is grossly mangling the
loop after inlining.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@158297 91177308-0d34-0410-b5e6-96231b3b80d8
lib/Transforms/InstCombine/InstCombineCompares.cpp
test/Transforms/InstCombine/icmp.ll