-
Notifications
You must be signed in to change notification settings - Fork 13.4k
Wrong code at -O2 on x86_64-linux_gnu since 3ddd1ff #68260
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
Labels
Comments
I believe the problem here is that we have a load from an addrec based on a constant global. The SCEV for the load will indeed always be Unknown, but the SCEVAtScope may not be: We can determine the exit value of the addrec and based on that determine the exit value of the load. |
I think this is a nice reduction: ; RUN: opt -S -passes='print<scalar-evolution>,loop(loop-unroll-full,indvars)' < %s
@g = constant [5 x i32] [i32 0, i32 1, i32 2, i32 3, i32 4]
declare void @use(i32)
define void @test() {
entry:
br label %loop
loop:
%iv = phi i64 [ 0, %entry ], [ %iv.next, %loop.latch ]
%iv.next = add i64 %iv, 1
br label %loop2
loop2:
%iv2 = phi i64 [ 0, %loop ], [ %iv2.next, %loop2 ]
%iv2.next = add i64 %iv2, 1
%idx = add i64 %iv, %iv2
%gep = getelementptr i32, ptr @g, i64 %idx
%load = load i32, ptr %gep
%cmp2 = icmp ne i64 %iv2, 3
br i1 %cmp2, label %loop2, label %loop.latch, !llvm.loop !0
loop.latch:
%load.lcssa = phi i32 [ %load, %loop2 ]
call void @use(i32 %load)
%cmp = icmp ne i64 %iv, 1
br i1 %cmp, label %loop, label %exit
exit:
ret void
}
!0 = distinct !{!0, !1}
!1 = !{!"llvm.loop.unroll.disable", i1 true} Results in: @g = constant [5 x i32] [i32 0, i32 1, i32 2, i32 3, i32 4]
declare void @use(i32)
define void @test() {
entry:
br label %loop
loop: ; preds = %entry
br label %loop2
loop2: ; preds = %loop2, %loop
br i1 false, label %loop2, label %loop.latch, !llvm.loop !0
loop.latch: ; preds = %loop2
call void @use(i32 4)
br label %loop2.1
loop2.1: ; preds = %loop2.1, %loop.latch
br i1 false, label %loop2.1, label %loop.latch.1, !llvm.loop !0
loop.latch.1: ; preds = %loop2.1
call void @use(i32 4)
ret void
}
!0 = distinct !{!0, !1}
!1 = !{!"llvm.loop.unroll.disable", i1 true} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
clang at -O2 produced the wrong code.
Bisected to 3ddd1ff, which was committed by @nikic
Compiler explorer: https://godbolt.org/z/rEv69ovMj
The text was updated successfully, but these errors were encountered: