This is an archive of the discontinued LLVM Phabricator instance.

InstCombine: Combine two icmps into one if the RHSs agree
Needs ReviewPublic

Authored by majnemer on Jul 31 2014, 11:27 AM.

Details

Summary

consider:
%cmp1 = icmp CC %V1, C
%cmp2 = icmp CC %V2, C
%and = and %cmp1, %cmp2

we can transform this into:
%or = or %V1, %V2
%cmp = icmp CC %or, C

This saves us an instruction and generates considerably nicer assembly
for X86, X86-64, arm, powerpc64 and aarch64.

Diff Detail

Event Timeline

majnemer updated this revision to Diff 12075.Jul 31 2014, 11:27 AM
majnemer retitled this revision from to InstCombine: Combine two icmps into one if the RHSs agree.
majnemer updated this object.
majnemer added reviewers: nicholas, bkramer.
majnemer added a subscriber: Unknown Object (MLST).
majnemer updated this revision to Diff 12077.Jul 31 2014, 11:40 AM
  • We only need to consider the uses of the and operands.
majnemer updated this revision to Diff 12086.Jul 31 2014, 3:00 PM
  • move the test from or.ll to and.ll
mcrosier added inline comments.
lib/Transforms/InstCombine/InstCombineAndOrXor.cpp
819

Perhaps,
Ty->isIntOrIntVectorTy()

822

Should this be

if (LHS->hasOneUse() && RHS->hasOneUse())

We should check to make sure the both compares have one and only one use, right?

mcrosier added inline comments.Aug 1 2014, 10:41 AM
lib/Transforms/InstCombine/InstCombineAndOrXor.cpp
814

Also, do we need a check to make sure the CCs match?

mcrosier added inline comments.Aug 2 2014, 9:56 AM
lib/Transforms/InstCombine/InstCombineAndOrXor.cpp
814

Nevermind, I see the check now..