-
-
Notifications
You must be signed in to change notification settings - Fork 14.9k
Range of index variables forgotten in an else if #144522
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.
LLVM issue: llvm/llvm-project#151078
Godbolt link
I expected the
assertto be optimized out, because the only possible values area/b/cwhich have been checked at the start of the function. However, in this case the bounds check seems to be lost, and theassertstays.The optimization failure happens when both conditions are met:
v[a]andv[b]). There's no problem when both conditions use the samev[a].else if. There's no problem if there's onlyif/elseeven if the conditions uses two different valuesif va < cond1 || vb < cond2Does not optimize:
Does optimize:
In C
va < cond1 || vb < cond2doens't optimize, butva < cond1 | vb < cond2does, so it may be related to extra branches.