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

[SCEV] Assertion `isAvailableAtLoopEntry(Op, L) && "SCEVAddRecExpr operand is not available at loop entry!"' failed. #117537

Closed
Nirhar opened this issue Nov 25, 2024 · 3 comments
Assignees
Labels
crash Prefer [crash-on-valid] or [crash-on-invalid] llvm:transforms

Comments

@Nirhar
Copy link
Contributor

Nirhar commented Nov 25, 2024

Faulty IR:

; ModuleID = 'test.ll'
source_filename = "/nfs/build-cache/zvm-dev-4598/jdk11/x86_64/fastdebug/lib/server/boilerplate.ll"
target datalayout = "e-m:e-p270:32:32-p271:32:32-p272:64:64-i64:64-i128:128-f80:128-n8:16:32:64-S128-ni:1-p2:32:8:8:32-ni:2"
target triple = "x86_64-unknown-linux-gnu"

define void @test(ptr addrspace(1) %p) {
entry:
  %check = icmp eq ptr addrspace(1) %p, null
  br label %bb0

bb0:                                              ; preds = %loop0, %entry
  br i1 %check, label %loop0, label %latch

latch:                                            ; preds = %bb0
  br i1 %check, label %exit0, label %loop0

exit0:                                            ; preds = %latch
  ret void

loop0:                                            ; preds = %latch, %bb0
  %0 = load atomic i32, ptr addrspace(1) %p unordered, align 8
  %add = add i32 %0, 3
  br i1 true, label %preheader, label %bb0

preheader:                                        ; preds = %loop0
  br label %loop1

loop1:                                            ; preds = %backedge, %preheader
  %iv1 = phi i32 [ %add, %preheader ], [ %1, %backedge ]
  %1 = add i32 %iv1, -33
  br label %loop2

backedge:                                         ; preds = %loop2
  br i1 true, label %exit1, label %loop1

loop2:                                            ; preds = %loop2, %loop1
  %iv0 = phi i32 [ %iv1, %loop1 ], [ %2, %loop2 ]
  %2 = add nsw i32 %iv0, 1
  %3 = icmp sgt i32 %2, 0
  br i1 %3, label %backedge, label %loop2

exit1:                                            ; preds = %backedge
  ret void
}

fails when run with opt -passes='print<scalar-evolution>,simple-loop-unswitch<nontrivial>,print<scalar-evolution>'
Demo of failure: https://godbolt.org/z/qhboK5r3j

@Nirhar
Copy link
Contributor Author

Nirhar commented Nov 25, 2024

Here is the IR after simple-loop-unswitch pass:
res

At the point of crash, the SCEV for Exit Value of %iv0(which I assume, as we crashed while printing it) is (-4 + (-1 * %1) + %.us-phi), which is incorrect. The crash happens because %1 is in a block that does not properly dominate %iv0. Looks like, simple-loop-unswitch is either incorrectly updating the SCEV in the pass, or is incorrectly reporting SCEV to be preserved. As of now, I'm not sure which is the case.

@EugeneZelenko EugeneZelenko added llvm:SCEV Scalar Evolution crash Prefer [crash-on-valid] or [crash-on-invalid] and removed new issue labels Nov 25, 2024
@Nirhar
Copy link
Contributor Author

Nirhar commented Nov 27, 2024

@nikic @dtcxzyw @EugeneZelenko any thoughts? I'm inclined to having a patch that removes SCEV from simple-loop-unswitch 's list of preserved analyses.

@dtcxzyw
Copy link
Member

dtcxzyw commented Nov 27, 2024

I'm inclined to having a patch that removes SCEV from simple-loop-unswitch 's list of preserved analyses.

Some SCEVs should be invalidated in unswitchNontrivialInvariants. Removing SCEV from the list of preserved analyses doesn't fix the issue.

@nikic nikic self-assigned this Nov 27, 2024
@nikic nikic closed this as completed in fc5c899 Nov 27, 2024
@EugeneZelenko EugeneZelenko added llvm:transforms and removed llvm:SCEV Scalar Evolution labels Nov 27, 2024
AZero13 pushed a commit to AZero13/llvm-project that referenced this issue Dec 5, 2024
AZero13 pushed a commit to AZero13/llvm-project that referenced this issue Dec 7, 2024
tru pushed a commit to AZero13/llvm-project that referenced this issue Dec 17, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
crash Prefer [crash-on-valid] or [crash-on-invalid] llvm:transforms
Projects
None yet
Development

No branches or pull requests

4 participants