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

Loop vectorizer may create redundant preheader and scalar loop #111098

Open
duk-37 opened this issue Oct 4, 2024 · 2 comments
Open

Loop vectorizer may create redundant preheader and scalar loop #111098

duk-37 opened this issue Oct 4, 2024 · 2 comments

Comments

@duk-37
Copy link
Contributor

duk-37 commented Oct 4, 2024

Compiler Explorer

#include <cstdint>

uint32_t foo(uint32_t *A, int n) {
  uint32_t sum = 0;
  for (int i = 0; i < n * 32; i++)
        sum += A[i];
  return sum;
}

Output IR is attached. I believe what's happening here is that the smax generated by SCEV expansion during IndVarSimplify interacts badly with SCEV checks in the loop vectorizer. I'm not quite sure though.

output.ll.txt

fhahn added a commit to fhahn/llvm-project that referenced this issue Oct 6, 2024
Use SCEV to check if the minimum iteration check (TC < Step) is known to
be false.

This is a first step towards addressing
llvm#111098. To catch
the exact case from the issue, we need to do extra work to make sure the
wrap flags on the shl are preserved and used by SCEV.
@fhahn
Copy link
Contributor

fhahn commented Oct 6, 2024

Basic support would be added with #111310. But there is extra work needed to preserve wrap flags on the mul/shl + using them from SCEV when computing the trip count expression

@fhahn
Copy link
Contributor

fhahn commented Oct 6, 2024

(alive proof for redundant RT check with nsw flag on shl: https://alive2.llvm.org/ce/z/PpNtgW)

fhahn added a commit that referenced this issue Oct 18, 2024
Use SCEV to check if the minimum iteration check (TC < Step) is known to
be false.

This is a first step towards addressing
#111098. To catch the exact
case from the issue, we need to do extra work to make sure the wrap
flags on the shl are preserved and used by SCEV.

Note that skeleton creation will be gradually moved to VPlan and this
simplification should be done as VPlan transform eventually. The current
plan is to move skeleton creation to VPlan starting from parts closest
to the parts already created by VPlan, starting with induction resume
value creation (started with
#110577), then memory and SCEV
checks and finally minimum iteration checks.

PR: #111310
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

2 participants