-
-
Notifications
You must be signed in to change notification settings - Fork 14.8k
Weird codegen / constant folding with iterators of length > 101 #112169
Copy link
Copy link
Open
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.C-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.
Metadata
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.C-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.
Type
Fields
Give feedbackNo fields configured for issues without a type.
Hi,
When playing with some of my code on compiler explorer, I found a case where rust would not compute the result of some functions at compile time. I managed to reduce the code to the following:
compiler explorer link
Both
test2andtest3are completely optimized and are compiled down to a singled "mov constant + ret" combo. But thetestfunction generates something quite convoluted: the compiler loads the result (102) and removes6from it until it reaches0, at which point it returns the value of another register to which6s have been added at each step.I tried a few versions of rustc but couldn't find any which completely optimized away the first function. Using
mir-opt-leveldidn't help.