rust-lang / rust-lang/rust

Suboptimal codegen for a function that should fold to a constant

Open
#130,421 3 comments 0 reactions 1 assignee View on GitHub

@deniskilseev is already working on this.

Since Sep 29, 2024.

A-codegen A-LLVM C-optimization I-slow T-compiler
Dominant language
Rust
Stars
119k
Forks
16.1k
PR merge metrics
PR metrics pending

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.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.