[PATCH] D154717: [LV] Check if ops can safely be truncated in computeMinimumValueSizes.

Nikita Popov via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Fri Jul 7 14:19:59 PDT 2023


nikic added inline comments.


================
Comment at: llvm/lib/Analysis/VectorUtils.cpp:678
+              if (I.trunc(MinBW).zext(I.getBitWidth()) == I)
+                return false;
+            }
----------------
fhahn wrote:
> nikic wrote:
> > Hm, is this special case for constants correct? Consider a variant on the test case that does something like `%l = shl i32 %f, 24`. Then only the low 8 bits of `%f` would be demanded, and `24` can be truncated to 8 bits, but it still changes the result: Now the shift would return poison (while previously the shl + trunc would produce zero).
> Yep, it seems like there are multiple issues with this code. For the `lshr` case, DemandedBits seems sufficient to rule out narrowing (by making sure we don't drop bits contributing to the result).
> 
> In addition to that for the `shl` case (and others where smaller widths may cause new poison), we would also need to take into account the semantics of the specific instructions. Do we have any existing APIs that would be suitable to check?
I think if we only use the demanded bits check below, that should always be correct. Would it be sufficient to only have the constant special case for shift amounts (with the appropriate bit width check)? That's probably the main case where we don't get meaningful demanded bits on one of the operands.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D154717/new/

https://reviews.llvm.org/D154717



More information about the llvm-commits mailing list