[llvm] [HashRecognize] Fix LHS ConstantRange check for BE (PR #148620)

Piotr Fusik via llvm-commits llvm-commits at lists.llvm.org
Fri Aug 1 08:43:08 PDT 2025


https://github.com/pfusik requested changes to this pull request.

I mean the whole `ValueEvolution` class is flawed if it only checks if we are shifting in zero bits.
For example, this get matched:

```llvm
for.body:                                         ; preds = %entry, %for.body
  %i.011 = phi i16 [ 0, %entry ], [ %inc, %for.body ]
  %crc.addr.010 = phi i16 [ %crc, %entry ], [ %cond, %for.body ]
  %shl = shl i16 %crc.addr.010, 1
  %evil1 = and i16 %i.011, 2
  %evil2 = add i16 %evil1, 1
  %evil = mul i16 %shl, %evil2
  %xor = xor i16 %evil, 4129
  %tobool.not9 = icmp slt i16 %crc.addr.010, 0
  %cond = select i1 %tobool.not9, i16 %xor, i16 %evil
  %inc = add nuw nsw i16 %i.011, 1
  %exitcond.not = icmp eq i16 %inc, 8
  br i1 %exitcond.not, label %for.cond.cleanup, label %for.body, !llvm.loop !9
```

Consider removing `ValueEvolution` and instead pattern-match the CRC calculation instructions. The whole analysis would be much simpler by matching the entire loop instead of looking for specific patterns here and there.

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


More information about the llvm-commits mailing list