-
Notifications
You must be signed in to change notification settings - Fork 12.5k
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
Wrong code at -O3 on x86_64 [14 regression since 0d95b20] #66986
Comments
Opt bisect points to an IndVars run with the following diff: https://gist.github.com/nikic/b241c38dcab5f27c652ebed27f371ebe This is an LFTR transform:
I haven't tried reasoning about the correctness of this, but what strikes me is that this is a very non-profitable transform. Not only do we insert an expensive exit count calculation, we also add a whole extra IV, plus an extra smax in the loop. |
Ah, the correctness problem is more obvious than I thought: We end up hoisting a division by zero here. We're missing an isSafeToExpand check in LFTR. |
Reduced: target datalayout = "n8:16:32:64"
define i32 @test(i1 %c, i32 %arg1, i32 %arg2) {
entry:
br label %loop
loop:
%phi = phi i32 [ %add9, %loop.latch ], [ 0, %entry ]
br i1 %c, label %if, label %loop.latch
if:
%udiv = udiv i32 %arg1, %arg2
%add = add i32 %udiv, %phi
%zext = zext i32 %add to i64
br label %loop2
loop2:
%phi6 = phi i64 [ %add7, %loop2 ], [ 0, %if ]
%add7 = add i64 %phi6, 1
%icmp = icmp slt i64 %phi6, %zext
br i1 %icmp, label %loop2, label %loop.latch
loop.latch:
%add9 = add i32 %phi, 1
br label %loop
} |
clang at -O3 produced the wrong code.
Bisected to 0d95b20, which was committed by @xortator
Compiler explorer: https://godbolt.org/z/o9Mdccsfe
The text was updated successfully, but these errors were encountered: