[all-commits] [llvm/llvm-project] 4def46: [flang] Fold fir.convert of an integer constant be...

Vijay Kandiah via All-commits all-commits at lists.llvm.org
Thu Sep 10 17:48:59 PDT 2026


  Branch: refs/heads/main
  Home:   https://github.com/llvm/llvm-project
  Commit: 4def46cc3fd51bee21f4a167a99a79c9f6bb66ba
      https://github.com/llvm/llvm-project/commit/4def46cc3fd51bee21f4a167a99a79c9f6bb66ba
  Author: Vijay Kandiah <vkandiah at nvidia.com>
  Date:   2026-09-10 (Thu, 10 Sep 2026)

  Changed paths:
    M flang/lib/Optimizer/Dialect/FIROps.cpp
    M flang/test/Fir/convert-fold.fir
    M flang/test/HLFIR/simplify-hlfir-intrinsics-eoshift.fir

  Log Message:
  -----------
  [flang] Fold fir.convert of an integer constant between integer types (#222188)

`fir::ConvertOp::fold` doesn't handle an integer constant converted to
another integer type. `ForwardConstantConvertPattern` covers the
neighboring case where the result is `index`, so `fir.convert %c10_i32 :
(i32) -> index` already canonicalizes to an index constant while
`fir.convert %c1_i32 : (i32) -> i64` does not. This PR adds the
integer-to-integer case.

The width change follows the rules codegen applies to a non-constant
operand (`CodeGen.cpp`'s integer-to-integer conversion): narrowing
truncates, widening zero-extends an i1 or unsigned source and
sign-extends anything else. The result must be signless because the
constant materialises as an `arith.constant`, which only accepts
signless integers.

It composes with `arith::IndexCastOp::fold`, so a value widened then
cast to `index` collapses to one index constant, and it lets other
patterns see through the constant: with a literal shift,
`simplify-hlfir-intrinsics` can now fold away `hlfir.eoshift`'s
shift-direction arithmetic.

`getIntIfConstant` only matches `arith` and `llvm` constants, which are
signless, so `isUnsignedInteger()` is never true today, but I still kept
the unsigned case anyway so that the fold cannot disagree with codegen.



To unsubscribe from these emails, change your notification settings at https://github.com/llvm/llvm-project/settings/notifications


More information about the All-commits mailing list