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

licm breaks volatile store in multiply-nested loops #1807

Closed
llvmbot opened this issue May 18, 2007 · 3 comments
Closed

licm breaks volatile store in multiply-nested loops #1807

llvmbot opened this issue May 18, 2007 · 3 comments
Assignees
Labels
bugzilla Issues migrated from bugzilla miscompilation

Comments

@llvmbot
Copy link
Collaborator

llvmbot commented May 18, 2007

Bugzilla Link 1435
Resolution FIXED
Resolved on Mar 06, 2010 13:59
Version 1.0
OS All
Attachments test_volatile.c
Reporter LLVM Bugzilla Contributor

Extended Description

I know that there is some recent discussions about the optimizations on
volatile loads and stores, and the conclusion is that LLVM is doing the right
thing. But this time the story seems different.

See below for details. The test case will be posted shortly.

=======================================================================
For my first example, LLVM is able to preserve both volatile load and store
correctly.

void PassThrough(volatile int* DataIn, volatile int* DataOut)
{
int i;
int buffer[64];

for (i = 0; i < 64; i++)
buffer[i] = *DataIn;

for (i = 0; i < 64; i++)
*DataOut = buffer[i];
}

=======================================================================
For the second one, however, LICM will move the volatile store outside of the
loop, which is apparently wrong.

void Transpose(volatile int* DataIn, volatile int* DataOut)
{
int i, j;
int buffer[64];

for (i = 0; i < 64; i++)
buffer[i] = *DataIn;

for (i = 0; i < 8; i++)
for (j = 0; j < 8; j++)
*DataOut = buffer[j * 8 + i];
}

=========================================================
What I did:

llvm-gcc -O0 -c -emit-llvm test_volatile.c -o test.bc
opt -mem2reg -licm test.bc -o new.bc -f

@llvmbot
Copy link
Collaborator Author

llvmbot commented May 18, 2007

assigned to @lattner

@lattner
Copy link
Collaborator

lattner commented May 18, 2007

This sounds like a real bug.

@lattner
Copy link
Collaborator

lattner commented May 23, 2007

Nice catch. This impacts nested loops only. Thanks for the excellent testcase reduction.

Fixed. Testcase here: Transforms/LICM/2007-05-22-VolatileSink.ll

Patch here:
http://lists.cs.uiuc.edu/pipermail/llvm-commits/Week-of-Mon-20070521/049945.html

-Chris

@llvmbot llvmbot transferred this issue from llvm/llvm-bugzilla-archive Dec 3, 2021
kitano-metro pushed a commit to RIKEN-RCCS/llvm-project that referenced this issue Mar 7, 2023
kitano-metro pushed a commit to RIKEN-RCCS/llvm-project that referenced this issue Mar 7, 2023
kitano-metro pushed a commit to RIKEN-RCCS/llvm-project that referenced this issue Mar 7, 2023
kitano-metro pushed a commit to RIKEN-RCCS/llvm-project that referenced this issue Mar 7, 2023
kitano-metro pushed a commit to RIKEN-RCCS/llvm-project that referenced this issue Mar 7, 2023
kitano-metro pushed a commit to RIKEN-RCCS/llvm-project that referenced this issue Mar 7, 2023
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 miscompilation
Projects
None yet
Development

No branches or pull requests

2 participants