[llvm] [InstCombine] Restore narrowing of double to float for integer casts (PR #190550)

Kavin Gnanapandithan via llvm-commits llvm-commits at lists.llvm.org
Mon Apr 6 13:10:24 PDT 2026


KavinTheG wrote:

Appreciate the reviews!

Applied review suggestions:
- refactored `canBeCastedExactlyIntToFP` to have a `CxtI` parameter to include knownbit analysis
```C++
  bool canBeCastedExactlyIntToFP(Value *V, Type *FPTy, bool IsSigned,
                                 const Instruction *CxtI = nullptr) const;
```
- added match statements, and called `canBeCastedExactlyIntToFP` with the fptrunc's `Ty` passed in, which in this case would be `f32`
- Added 2 more test cases 
	- `@fdiv_narrow_urem_within_float_range/@fdiv_narrow_urem_outside_float_range` to see if InstCombine will still narrow to a float if `%1` (which I think would correspond to `Src` in the match statement) is too big to fit within a `float`
	  - it seems that even if %1 is too big, `sitofp to float` -> `fpext float to double` will let it stay in float. So i made the extra positive case without `fpext`

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


More information about the llvm-commits mailing list