[llvm] [InstCombine] limit icmp sgt (shl nsw X, C1), C0 --> icmp sgt X, C0 >> C1 to hasOneUse (PR #74318)

Liao Chunyu via llvm-commits llvm-commits at lists.llvm.org
Wed Feb 28 18:52:27 PST 2024


ChunyuLiao wrote:

I guess I found where SCEV takes effect against this patch in:
https://github.com/llvm/llvm-project/blob/main/llvm/lib/Analysis/ScalarEvolution.cpp#L11872
```
std::optional<APInt>
ScalarEvolution::computeConstantDifference(const SCEV *More, const SCEV *Less) {
  // We avoid subtracting expressions here because this function is usually
  // fairly deep in the call stack (i.e. is called many times).

  // X - X = 0.
  if (More == Less)
    return APInt(getTypeSizeInBits(More->getType()), 0);
```
There are some optimizations for SCEVAddRecExpr and SCEVAddExpr in computeConstantDifference, but in this example it's: SCEVType = llvm::scUnknown, so it can't be handled

https://github.com/llvm/llvm-project/pull/74318


More information about the llvm-commits mailing list