Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[RISCV][LoopUnroll/CostModel] Loops with Insert/Extract element using induction variable without vector are not unrolled #92366

Open
joe-img opened this issue May 16, 2024 · 2 comments

Comments

@joe-img
Copy link

joe-img commented May 16, 2024

Without vector, extractelement/insertelement with non-constant index can be very costly.
This was factored into the cost model in #67334

However, in the case of full canonical loop unrolling and the index being the induction variable, the index will be constant, but is not at the time of estimating the cost of unrolling the loop.

Example before and after this change: (llvm 17 vs 18)
https://compiler-explorer.com/z/Mh6eWKjr7

I had a go at fixing this myself, but could not see a good fix. I ended up abusing ephemeral values that get passed into UnrollCostEstimator.

@llvmbot
Copy link
Collaborator

llvmbot commented May 16, 2024

@llvm/issue-subscribers-backend-risc-v

Author: Joe Faulls (joe-img)

Without vector, extractelement/insertelement with non-constant index can be very costly. This was factored into the cost model in https://github.com//pull/67334

However, in the case of full canonical loop unrolling and the index being the induction variable, the index will be constant, but is not at the time of estimating the cost of unrolling the loop.

Example before and after this change: (llvm 17 vs 18)
https://compiler-explorer.com/z/Mh6eWKjr7

I had a go at fixing this myself, but could not see a good fix. I ended up abusing ephemeral values that get passed into UnrollCostEstimator.

@asb
Copy link
Contributor

asb commented May 20, 2024

This wouldn't fix the general problem, but at least for the kind of example you shared (simple vector initialisation expressed using a loop), I wonder if it would make sense to do something in LoopIdiomRecognize to detect that pattern and replace the loop with logic that sets a constant vec value.

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

No branches or pull requests

5 participants