[llvm] [InstCombine] Optimize (select %x, op(%x), 0) to op(%x) for operations where op(0) == 0 (PR #147605)

Nikita Popov via llvm-commits llvm-commits at lists.llvm.org
Sat Jul 12 03:12:42 PDT 2025


================
@@ -7318,6 +7318,25 @@ bool llvm::isOverflowIntrinsicNoWrap(const WithOverflowInst *WO,
 
 /// Shifts return poison if shiftwidth is larger than the bitwidth.
 static bool shiftAmountKnownInRange(const Value *ShiftAmount) {
+  auto *A = dyn_cast<Argument>(ShiftAmount);
+  if (A) {
+    auto Range = A->getRange();
+    if (Range && Range->getUnsignedMax().ult(
+                     ShiftAmount->getType()->getIntegerBitWidth())) {
----------------
nikic wrote:

This should use getScalarSizeInBits(), otherwise it will crash for vector shifts. Same below.

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


More information about the llvm-commits mailing list