[PATCH] D53659: [ValueTracking] peek through shuffles in ComputeNumSignBits (PR37549)

Eli Friedman via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Wed Oct 24 11:11:35 PDT 2018


efriedma added inline comments.


================
Comment at: lib/Analysis/ValueTracking.cpp:2515
+  case Instruction::ShuffleVector:
+    // Look through shuffle of 1 source vector.
+    if (isa<UndefValue>(U->getOperand(0)))
----------------
spatel wrote:
> RKSimon wrote:
> > Do we know for certain that we don't reference an under operand at this point? SelectionDAG::ComputeNumSignBits bails i such cases.
> I saw that, but I wasn't sure why bailing was necessary (in IR at least). 
> 
> If the shuffle's mask contains an undef, then the result for that lane is undef:
> http://llvm.org/docs/LangRef.html#shufflevector-instruction
> 
> So we can choose 0 or -1 for that undef element, and so it can't reduce the number of sign bits?
We can pick any value for an undef, but every optimization has to handle it consistently.  So you can't assume it's 0 unless you actually replace it with zero.

In this particular case, instead of looking for UndefValues, could you examine the mask instead?


https://reviews.llvm.org/D53659





More information about the llvm-commits mailing list