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

GVNHoist leads to miscompile of llvm test-suite SingleSource/Benchmarks/Misc/fbench.c #29250

Closed
MatzeB opened this issue Aug 6, 2016 · 9 comments
Labels
bugzilla Issues migrated from bugzilla

Comments

@MatzeB
Copy link
Contributor

MatzeB commented Aug 6, 2016

Bugzilla Link 28880
Resolution FIXED
Resolved on Aug 08, 2016 09:50
Version trunk
OS All
CC @gburgessiv,@hfinkel,@sebpop

Extended Description

GVN-hoist appears to miscompile SingleSource/Benchmarks/Misc/fbench.c as this builder:

http://lab.llvm.org:8080/green/job/Performance_O3flto/

is broken after r277786 "GVN-hoist: enable by default".

Citing Sebastians analysis: "

think there is a problem with the MemorySSA when compiling fbench with -Ofast
The problem appears with -mllvm -gvn-max-hoisted=63, (at 62 the
program is not miscompiled.)
before.ll is the MSSA dump at 62 and after.ll is the MSSA for 63.

We end up hoisting two loads past a store, and the loads do not link
to the store: they are both liveOnEntry:

; MemoryUse(liveOnEntry)
%19 = load double, double* @​axis_slope_angle, align 8, !tbaa !​5

and

; MemoryUse(liveOnEntry)
%22 = load double, double* @​axis_slope_angle, align 8, !tbaa !​5

past a store to the global variable:

; 7 = MemoryDef(liveOnEntry)
store double 0.000000e+00, double* @​axis_slope_angle, align 8, !tbaa !​5
"

@MatzeB
Copy link
Contributor Author

MatzeB commented Aug 6, 2016

I reverted r277786 in the meantime (in r277909)

@sebpop
Copy link
Mannequin

sebpop mannequin commented Aug 6, 2016

Preprocessed testcase
Compile the attached file with:

$ clang -Ofast fbench.i -fblocks -o a.out -lm -mllvm -gvn-max-hoisted=63
$ ./a.out
[...]
93 errors in results. This is VERY SERIOUS.

$ clang -Ofast fbench.i -fblocks -o a.out -lm -mllvm -gvn-max-hoisted=62
$ ./a.out
[...]
No errors in results.

@sebpop
Copy link
Mannequin

sebpop mannequin commented Aug 6, 2016

@sebpop
Copy link
Mannequin

sebpop mannequin commented Aug 6, 2016

@llvmbot
Copy link
Collaborator

llvmbot commented Aug 6, 2016

Complete dump you can use to see incorrect version
use opt -tbaa -print-memoryssa to see:

if.then22: ; preds = %if.then20
; 7 = MemoryDef(liveOnEntry)
store double 0.000000e+00, double* @​axis_slope_angle, align 8, !tbaa !​3
...

; 13 = MemoryPhi({if.then22,7},{if.else24,liveOnEntry})
...

; MemoryUse(liveOnEntry)
%22 = load double, double* @​axis_slope_angle, align 8, !tbaa !​3

@llvmbot
Copy link
Collaborator

llvmbot commented Aug 6, 2016

@llvmbot
Copy link
Collaborator

llvmbot commented Aug 6, 2016

This is a silly bug: We are trying to figure out whether the size of the stack has changed due to popping off non-dominating accesses,and we are not doing it right:

We were doing:
if (LocInfo.LowerBound >= VersionStack.size() - 1) {

To see if the lower bound needed to be reset after popping the stack.
The problem with this is that if you have any pushes, it may be that the lower bound is still wrong, the size will still now be "right".

The correct fix is to store the size of the stack after we are done popping, and use it in the comparison above.

Ironically, I had thought about this, and in the first versions of the use optimizer i sent george, we were storing the stack size, but i couldn't remember why we needed to do that so i removed it :)

I'll fix this and add a testcase.

@llvmbot
Copy link
Collaborator

llvmbot commented Aug 6, 2016

Patch that should fix it

@sebpop
Copy link
Mannequin

sebpop mannequin commented Aug 8, 2016

Fixed in https://reviews.llvm.org/rL277978
and enabled gvn-hoist by default in https://reviews.llvm.org/rL278010

@llvmbot llvmbot transferred this issue from llvm/llvm-bugzilla-archive Dec 10, 2021
This issue was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bugzilla Issues migrated from bugzilla
Projects
None yet
Development

No branches or pull requests

2 participants