Skip to content

[CIR] Generate SelectOp instead of TernaryOp for if cheap enough to evaluate unconditionally #1642

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
May 23, 2025

Conversation

mmha
Copy link
Collaborator

@mmha mmha commented May 23, 2025

This came up during the review of llvm/llvm-project#138156

During codegen we check whether the LHS and RHS of the conditional operator are cheap enough to evaluate uncondionally. Unlike classic codegen we still emit TernaryOp instead of SelectOp and defer that optimization to cir-simplify.

This patch changes codegen to directly emit SelectOp for cond ? constant : constant expressions.

@mmha mmha requested review from lanza and bcardosolopes as code owners May 23, 2025 16:41
@mmha
Copy link
Collaborator Author

mmha commented May 23, 2025

I deleted clang/test/CIR/Transforms/ternary-fold.cpp because all test cases inside that file are now handled by codegen so cir-simlify has nothing to do here. I do wonder whether SimplifyTernary still has a use.

Copy link
Member

@bcardosolopes bcardosolopes left a comment

Choose a reason for hiding this comment

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

Thanks Morris! LGTM

@bcardosolopes bcardosolopes merged commit 791c327 into llvm:main May 23, 2025
10 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.

2 participants