[llvm] [ValueTracking] Fix Overflow with i1 Constant GEPs (PR #125470)

Nikita Popov via llvm-commits llvm-commits at lists.llvm.org
Mon Feb 3 08:56:15 PST 2025


================
@@ -1477,8 +1477,11 @@ static void computeKnownBitsFromOperator(const Operator *I,
         // that this is a multiple of the minimum size.
         ScalingFactor.Zero.setLowBits(llvm::countr_zero(TypeSizeInBytes));
       } else if (IndexBits.isConstant()) {
-        APInt IndexConst = IndexBits.getConstant();
-        APInt ScalingFactor(IndexBitWidth, TypeSizeInBytes);
+        // i1 is a valid GEP index, ensure we have enough space to do the
+        // computation in that case.
+        unsigned CalcBitWidth = std::max(IndexBitWidth, 8u);
+        APInt IndexConst = IndexBits.getConstant().zext(CalcBitWidth);
+        APInt ScalingFactor(CalcBitWidth, TypeSizeInBytes);
----------------
nikic wrote:

Here it is: https://github.com/llvm/llvm-project/pull/125532

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


More information about the llvm-commits mailing list