-
Notifications
You must be signed in to change notification settings - Fork 12.9k
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
multi-dimensional VLA indicies not scaled by llvm-gcc #1605
Comments
assigned to @lattner |
The online demo is currently pointing at some UIUC developer's build tree, AFAIK. Have you replicated this problem on the head of LLVM/llvm-gcc? If not, please do so. If it still doesn't work, we'll investigate. |
This fails with mainline as well: define i32 @foo(i32 %v, i32 %w, i32 %x, i32 %y, i32 %z, float* %A, i32 %g, i32 %h, i32 %i, i32 %j, i32 %k) { certainly a CFE bug. |
Nice catch. Testcase here: Patch here: The patch generates pretty horrible LLVM code (in the VLA case only), but the code generator groks it _foo: GCC apparently misses reassociating some arithmetic and does significantly worse: _foo: I'd appreciate it if you could verify that the code we now produce is correct. I verified a simpler case. Thanks again for noticing this, -Chris |
FWIW, here is the generated LLVM code: define i32 @foo(i32 %v, i32 %w, i32 %x, i32 %y, i32 %z, float* %A, i32 %g, i32 %h, i32 %i, i32 %j, i32 %k) { |
That new LLVM code still isn't right. The g index is scaled now, but h, i, and j |
That explains the difference in codegen. Sorry, I was very tired last night. It looks like it requires multiple |
Okay, here's the second half of the patch, which handles the ARRAY_REF array case (previous patch With this, we now compile: int foo(int v, int w, int x, int y, int z, into: _foo: ... which looks right to me. GCC produces this, which is also right, but just worse code: _foo: We now compile your full case to: _foo2: GCC produces: _foo2: Please verify that the new codegen is correct. Thanks again, -Chris |
This still doesn't work on i686-pc-linux-gnu |
Is this still failing for you? It works for me, and this isn't target-specific code. -Chris |
The latest output posted for the full test case executes correctly for me on |
Sounds good, I will assume it was just something transient in Reid's tree. |
…70d63b13dd51638c1424 [lldb] Make UBSan tests remote ready
Extended Description
I typed this into the online demo:
int foo(int v, int w, int x, int y, int z,
float A[][w][x][y][z],
int g, int h, int i, int j, int k)
{
return A[g][h][i][j][k];
}
It gave me this:
int %foo(int %v, int %w, int %x, int %y, int %z, float* %A, int %g, int %h, int
%i, int %j, int %k) {
entry:
%tmp64.sum = add int %h, %g ; [#uses=1]
%tmp62.sum = add int %tmp64.sum, %i ; [#uses=1]
%tmp60.sum = add int %tmp62.sum, %j ; [#uses=1]
%tmp54.sum = add int %tmp60.sum, %k ; [#uses=1]
%tmp66 = getelementptr float* %A, int %tmp54.sum ; <float*> [#uses=1]
%tmp = load float* %tmp66 ; [#uses=1]
%tmp67 = cast float %tmp to int ; [#uses=1]
ret int %tmp67
}
The VLA indicies are not being scaled; it's just adding them all up verbatim and
doing a one-dimensional getelementptr.
The text was updated successfully, but these errors were encountered: