For rdar://12329730, last piece.
authorShuxin Yang <shuxin.llvm@gmail.com>
Tue, 4 Dec 2012 22:15:32 +0000 (22:15 +0000)
committerShuxin Yang <shuxin.llvm@gmail.com>
Tue, 4 Dec 2012 22:15:32 +0000 (22:15 +0000)
commita09e18fcfab0e998526724357f8fc5ef7f4c3e7a
treeae8edcd6a6d4c443904d32759291fe09ec4815f8
parent836cfc46b38969acc2f74af099b51d0b567f498d
  For rdar://12329730, last piece.

  This change attempts to simplify (X^Y) -> X or Y in the user's context if we know that
only bits from X or Y are demanded.

  A minimized case is provided bellow. This change will simplify "t>>16" into "var1 >>16".

  =============================================================
  unsigned foo (unsigned val1, unsigned val2) {
    unsigned t = val1 ^ 1234;
    return (t >> 16) | t; // NOTE: t is used more than once.
  }
  =============================================================

  Note that if the "t" were used only once, the expression would be finally optimized as well.
However, with with this change, the optimization will take place earlier.

  Reviewed by Nadav, Thanks a lot!

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@169317 91177308-0d34-0410-b5e6-96231b3b80d8
lib/Transforms/InstCombine/InstCombineSimplifyDemanded.cpp
test/Transforms/InstCombine/2010-11-01-lshr-mask.ll
test/Transforms/InstCombine/shift.ll
test/Transforms/InstCombine/xor2.ll