[llvm] [RISCV] Use APInt in isSimpleVIDSequence to account for index overflow (PR #100072)

Philip Reames via llvm-commits llvm-commits at lists.llvm.org
Mon Jul 29 08:46:49 PDT 2024


================
@@ -3451,9 +3455,11 @@ static std::optional<VIDSequence> isSimpleVIDSequence(SDValue Op,
   for (auto [Idx, Elt] : enumerate(Elts)) {
     if (!Elt)
       continue;
-    uint64_t ExpectedVal =
-        (int64_t)(Idx * (uint64_t)*SeqStepNum) / *SeqStepDenom;
-    int64_t Addend = SignExtend64(*Elt - ExpectedVal, EltSizeInBits);
+    APInt ExpectedVal(EltSizeInBits, Idx);
+    ExpectedVal *= *SeqStepNum;
+    ExpectedVal = ExpectedVal.sdiv(*SeqStepDenom);
----------------
preames wrote:

Minor, but you can write this as:
APInt ExpectedVal = (APInt(EltSizeInBits, Idx) * *SeqStepNum).sdiv(*SeqStepDenum);

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


More information about the llvm-commits mailing list