Skip to content

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
terapines-osc-cir pushed a commit to Terapines/clangir that referenced this pull request Sep 2, 2025
…valuate unconditionally (llvm#1642)

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.
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