[PATCH] D83127: [InstCombine] canEvaluateTruncated - use KnownBits to check for inrange shift amounts

Simon Pilgrim via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Fri Jul 3 06:58:38 PDT 2020


RKSimon marked an inline comment as done.
RKSimon added inline comments.


================
Comment at: llvm/lib/Transforms/InstCombine/InstCombineCasts.cpp:398
+        llvm::computeKnownBits(I->getOperand(1), IC.getDataLayout());
+    APInt ShiftedBits = APInt::getBitsSetFrom(OrigBitWidth, BitWidth);
+    if (AmtKnownBits.getMaxValue().ult(BitWidth) &&
----------------
lebedev.ri wrote:
> Shouldn't this take `AmtKnownBits.getMaxValue()` into account?
> 
> I.e. if we are truncating `i32 -> i16`, but are shifting by at most `1`,
> we don't need for all bits under mask `0xFFFF0000` to be zeros,
> we only need that for the bits we'd potentially shift-in,
> i.e. only `0x10000`. Or am i missing something?
You're right - this is an existing issue - do you want me to deal with that first?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D83127





More information about the llvm-commits mailing list