-
Notifications
You must be signed in to change notification settings - Fork 10.7k
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
Dead Code Elimination Regression at -O3 (trunk vs. 14.0.4) #56048
Comments
Why do we get the freeze in the first place? |
Answering myself, it's loop unswitch. In this case we could forgo the freeze, because we have smth like: %h.0 = phi i32 [ 1, %entry ], [ %sub, %for.inc10 ]
%cmp4 = icmp eq i32 %h.0, 1
%cmp4.fr = freeze i1 %cmp4
...
%sub = add nsw i32 %h.0, -1 The initial phi value is non-poison, and the subsequent value is also not poison (if we drop nsw), so loop unswitch could have avoided adding the freeze by dropping nsw (which in retrospect that's what your proposed patch does). The reason I was looking into this is because dropping nsw from induction variables is not great. It can make SCEV unable to compute the trip count. |
Mentioned patch for reference: https://reviews.llvm.org/D127960
SCEV can't analyze freeze instructions, so it will not be able to even form an addrec in this case, let alone compute a trip count. I think that pushing the freeze to the start value (so we can form the addrec) should generally be preferable to keeping nowrap flags. |
True, and freeze kills the nsw anyway, so getting rid of freeze is the way to go, yes. |
llvm-4c2bccfda3892ae13e97b6bfdbc99ec8cf5d095d (trunk) -O3
can not eliminatefoo
butllvm-llvmorg-14.0.4 -O3
can.Target:
x86_64-unknown-linux-gnu
llvm-4c2bccfda3892ae13e97b6bfdbc99ec8cf5d095d (trunk) -O3 [-emit-llvm] -S -o /dev/stdout case.c
Reduced assembly
llvm-llvmorg-14.0.4 -O3 [-emit-llvm] -S -o /dev/stdout case.c
Reduced assembly
Bisection
Bisected to: 6001bfc
Committed by: @nikic
The text was updated successfully, but these errors were encountered: