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

[LoopIdiomRecognize] Poison flags stripped even though no transform performed #82337

Closed
nikic opened this issue Feb 20, 2024 · 1 comment · Fixed by #82362
Closed

[LoopIdiomRecognize] Poison flags stripped even though no transform performed #82337

nikic opened this issue Feb 20, 2024 · 1 comment · Fixed by #82362
Assignees
Labels
llvm:SCEV Scalar Evolution

Comments

@nikic
Copy link
Contributor

nikic commented Feb 20, 2024

In this example, LIR will remove the nuw/exact flags on %dist and %len, even though it does not actually perform any transform:

; RUN: opt -S -passes=loop-idiom < %s
define void @test(ptr %p.end, ptr %p.start) {
entry:
  %p.end.int = ptrtoint ptr %p.end to i64
  %p.start.int = ptrtoint ptr %p.start to i64
  %dist = sub nuw i64 %p.end.int, %p.start.int
  %len = lshr exact i64 %dist, 5
  %cmp = icmp eq ptr %p.end, %p.start
  br i1 %cmp, label %exit, label %preheader

preheader:
  br label %loop

loop:
  %iv = phi i64 [ %len, %preheader ], [ %iv.dec, %loop ]
  %iv.neg = sub nsw i64 0, %iv
  %src = getelementptr inbounds [32 x i8], ptr %p.end, i64 %iv.neg
  %v = load <4 x i64>, ptr %src, align 8
  %dst = getelementptr inbounds [32 x i8], ptr %p.start, i64 %iv.neg
  store <4 x i64> %v, ptr %dst, align 8
  %iv.dec = add i64 %iv, -1
  %cmp2 = icmp eq i64 %iv.dec, 0
  br i1 %cmp2, label %loop.exit, label %loop

loop.exit:
  br label %exit

exit:
  ret void
}
@nikic
Copy link
Contributor Author

nikic commented Feb 20, 2024

processLoopStoreOfLoopLoad() uses SCEVExpanderCleaner, which removes newly inserted instructions, but does not restore modified flags.

@nikic nikic added loopoptim llvm:SCEV Scalar Evolution and removed new issue labels Feb 20, 2024
@nikic nikic self-assigned this Feb 20, 2024
nikic added a commit that referenced this issue Feb 20, 2024
nikic added a commit to nikic/llvm-project that referenced this issue Feb 20, 2024
SCEVExpanderCleaner will currently remove instructions created
by SCEVExpander, but not restore poison generating flags that it
may have dropped. As such, running LIR can currently spuriously
drop flags without performing any transforms.

Fix this by keeping track of original instruction flags in
SCEVExpander.

Fixes llvm#82337.
nikic added a commit to nikic/llvm-project that referenced this issue Feb 21, 2024
SCEVExpanderCleaner will currently remove instructions created
by SCEVExpander, but not restore poison generating flags that it
may have dropped. As such, running LIR can currently spuriously
drop flags without performing any transforms.

Fix this by keeping track of original instruction flags in
SCEVExpander.

Fixes llvm#82337.
nikic added a commit that referenced this issue Feb 21, 2024
…82362)

SCEVExpanderCleaner will currently remove instructions created by
SCEVExpander, but not restore poison generating flags that it may have
dropped. As such, running LIR can currently spuriously drop flags
without performing any transforms.

Fix this by keeping track of original instruction flags in SCEVExpander.

Fixes #82337.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
llvm:SCEV Scalar Evolution
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants