Skip to content

Conversation

mdazz
Copy link
Contributor

@mdazz mdazz commented Sep 5, 2025

This commit teaches AtenToDtypeOp::fold to constant-fold dtype conversions when the operand is a splat DenseElementsAttr.

Folding is done according to torch's rounding behavior, i.e.

  • Bool: 0 and -0.0 → false; nonzero/NaN/±Inf → true.
  • Float → Int: round toward zero.
  • Int → Float: sign-aware, rmNearestTiesToEven.
  • Float ↔ Float: use builtin mlir::FloatType::getFloatSemantics().
  • Int ↔ Int: use zextOrTrunc / sextOrTrunc based on source signedness.

Folding is only performed when non_blocking == false, copy == false, and memory_format is None.

@mdazz
Copy link
Contributor Author

mdazz commented Sep 5, 2025

Not sure who can review, maybe you would know @vivekkhandelwal1 @zjgarvey ?

@mdazz mdazz force-pushed the mdazz/add-todtype-folder branch 2 times, most recently from 9b8168c to 42edabd Compare September 15, 2025 10:06
This commit teaches `AtenToDtypeOp::fold` to constant-fold dtype conversions
when the operand is a splat `DenseElementsAttr`.

Folding is done according to torch's rounding behavior, i.e.
  * Bool: 0 and -0.0 → false; nonzero/NaN/±Inf → true.
  * Float → Int: round toward zero.
  * Int → Float: sign-aware, rmNearestTiesToEven.
  * Float ↔ Float: use builtin `mlir::FloatType::getFloatSemantics()`.
  * Int ↔ Int: use `zextOrTrunc` / `sextOrTrunc` based on source signedness.

Folding is only performed when `non_blocking == false`, `copy == false`, and `memory_format` is None.
@mdazz mdazz force-pushed the mdazz/add-todtype-folder branch from 42edabd to 3abbd48 Compare September 16, 2025 08:45
Copy link
Collaborator

@zjgarvey zjgarvey left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the folder improvements! Sorry for the long turnaround.

Copy link
Member

@sahas3 sahas3 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry this one slipped through the cracks. LGTM.

One suggestion for future is to not amend the git commit for changes that has been reviewed already when addressing feedback, so that it's easy for reviewers to only review the changes since the last feedback was provided. Thanks!

@sahas3 sahas3 merged commit cedf522 into llvm:main Sep 29, 2025
3 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants