[llvm] [InstCombine][NFC] Use uint64_t for TruncRatio to avoid overflow (PR #225150)

via llvm-commits llvm-commits at lists.llvm.org
Mon Sep 21 10:48:56 PDT 2026


llvmorg-github-actions[bot] wrote:


<!--LLVM PR SUMMARY COMMENT-->

@llvm/pr-subscribers-llvm-transforms

Author: ahradwan2-public

<details>
<summary>Changes</summary>

## Summary
This changes `TruncRatio` from `unsigned` to `uint64_t` in `foldVecExtTruncToExtElt`

    unsigned TruncRatio = SrcBits / DstBits;

`BitCastNumElts` is used to build the destination vector type with `TruncRatio` declared `unsigned`, this product is evaluated in 32 bits.

    BitCastNumElts = VecElts.getKnownMinValue() * TruncRatio;

 An overflow would wrap to a small value that silently satisfies the existing

    assert(BitCastNumElts <= std::numeric_limits<uint32_t>::max() &&
           "overflow 32-bits");

and construct a wrong-sized vector type. Declaring `TruncRatio` as `uint64_t` computes the true 64-bit product, so the assert is actually meaningful.

#### Assisted by: Cline
#### I don't have write access - please merge on my behalf once approved. Thanks.

---
Full diff: https://github.com/llvm/llvm-project/pull/225150.diff


1 Files Affected:

- (modified) llvm/lib/Transforms/InstCombine/InstCombineCasts.cpp (+1-1) 


``````````diff
The server is unavailable at this time. Please wait a few minutes before you try again.
``````````

</details>


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


More information about the llvm-commits mailing list