[ValueTracking] Extend r251146 to catch a fairly common case
authorJames Molloy <james.molloy@arm.com>
Mon, 26 Oct 2015 14:10:46 +0000 (14:10 +0000)
committerJames Molloy <james.molloy@arm.com>
Mon, 26 Oct 2015 14:10:46 +0000 (14:10 +0000)
commitbf7b3fed5c75e7256ac395c01a7770edb20735e8
tree82e8a6df497c56cce91ebc0289616dd217bd2fcf
parentbd8522817da585714a793d850da7e3eafc79b139
[ValueTracking] Extend r251146 to catch a fairly common case

Even though we may not know the value of the shifter operand, it's possible we know the shifter operand is non-zero. This can allow us to infer more known bits - for example:

  %1 = load %p !range {1, 5}
  %2 = shl %q, %1

We don't know %1, but we do know that it is nonzero so %2[0] is known zero, and importantly %2 is known non-zero.

Calling isKnownNonZero is nontrivially expensive so use an Optional to run it lazily and cache its result.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@251294 91177308-0d34-0410-b5e6-96231b3b80d8
lib/Analysis/ValueTracking.cpp
test/Analysis/ValueTracking/knownnonzero-shift.ll [new file with mode: 0644]