Skip to content

Suboptimal codegen for a function that should fold to a constant #130421

Open

Description

I'm not entirely sure whether this belongs to LLVM or rust (I haven't triaged), but let's start here.

I tried this code: https://godbolt.org/z/E5W74re7v
which could potentially folded to a single constant, but the optimizer fails to recognize.

Changing the inner if condition from t + s + r == 10 to t + s == 10 results into the LLVM IR being a single line function:
ret i64 63000000000. In godbolt: https://godbolt.org/z/zfchrszbW

I would expect both cases to fold to a constant, but maybe I'm missing something here.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Assignees

Labels

A-LLVMArea: Code generation parts specific to LLVM. Both correctness bugs and optimization-related issues.Area: Code generation parts specific to LLVM. Both correctness bugs and optimization-related issues.A-codegenArea: Code generationArea: Code generationC-optimizationCategory: An issue highlighting optimization opportunities or PRs implementing suchCategory: An issue highlighting optimization opportunities or PRs implementing suchI-slowIssue: Problems and improvements with respect to performance of generated code.Issue: Problems and improvements with respect to performance of generated code.T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.Relevant to the compiler team, which will review and decide on the PR/issue.

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions