<html>
    <head>
      <base href="https://llvm.org/bugs/" />
    </head>
    <body><table border="1" cellspacing="0" cellpadding="8">
        <tr>
          <th>Bug ID</th>
          <td><a class="bz_bug_link 
          bz_status_NEW "
   title="NEW --- - [Polly] Loop invariant code motion, structures and non-power-of-two types cause miscompile"
   href="https://llvm.org/bugs/show_bug.cgi?id=25505">25505</a>
          </td>
        </tr>

        <tr>
          <th>Summary</th>
          <td>[Polly] Loop invariant code motion, structures and non-power-of-two types cause miscompile
          </td>
        </tr>

        <tr>
          <th>Product</th>
          <td>Projects
          </td>
        </tr>

        <tr>
          <th>Version</th>
          <td>unspecified
          </td>
        </tr>

        <tr>
          <th>Hardware</th>
          <td>PC
          </td>
        </tr>

        <tr>
          <th>OS</th>
          <td>Linux
          </td>
        </tr>

        <tr>
          <th>Status</th>
          <td>NEW
          </td>
        </tr>

        <tr>
          <th>Severity</th>
          <td>normal
          </td>
        </tr>

        <tr>
          <th>Priority</th>
          <td>P
          </td>
        </tr>

        <tr>
          <th>Component</th>
          <td>Polly
          </td>
        </tr>

        <tr>
          <th>Assignee</th>
          <td>polly-dev@googlegroups.com
          </td>
        </tr>

        <tr>
          <th>Reporter</th>
          <td>tobias@grosser.es
          </td>
        </tr>

        <tr>
          <th>CC</th>
          <td>llvm-bugs@lists.llvm.org
          </td>
        </tr>

        <tr>
          <th>Classification</th>
          <td>Unclassified
          </td>
        </tr></table>
      <p>
        <div>
        <pre>With 252860 Polly currently miscompiles LNT MultiSource/Applications/obsequi.

The miscompilation is in hash.c:hashlookup at the last
LOOKUP_ENTRY(g_flipVH_hashkey) call.

Two issues I see:

1) We hoist loads from Non-Affine Region Statements. For such statements we
   do not necessarily know that loads will be executed, hence hoisting them
   may cause segfaults (may not be part of the issue here)

2) When creating access locations we generate incorrect code in case number of
bytes and actual allocation size of a type do not match. Below is a patch that
might fix this, but it has not yet been properly tested and is possibly
incomplete.


@@ -171,6 +171,18 @@ Value *IslExprBuilder::createAccessAddress(isl_ast_expr
*Expr) {
         Builder.CreateMul(IndexOp, DimSize, "polly.access.mul." + BaseName);
   }

+  auto &DL =
+      Builder.GetInsertBlock()->getParent()->getParent()->getDataLayout();
+  unsigned int StorageSize = DL.getTypeAllocSize(SAI->getElementType());
+  unsigned int ElementSize = SAI->getElemSizeInBytes();
+  if (!SAI->getElementType()->isPointerTy() && ElementSize != StorageSize) {
+    Value *ElementValue = Builder.getInt8(ElementSize);
+    Value *StorageValue = Builder.getInt8(StorageSize);
+    ElementValue = Builder.CreateSExt(ElementValue, IndexOp->getType());
+    StorageValue = Builder.CreateSExt(StorageValue, IndexOp->getType());
+    IndexOp = Builder.CreateMul(IndexOp, ElementValue);
+    IndexOp = Builder.CreateSDiv(IndexOp, StorageValue);
+  }

This patch prevents us from segfaulting for this test case.

3) Even with this patch applied, we still miscompile the test case. I have no
idea what is going on.


I need to move to other stuff know, but if someone could have a look that would
be appreciated.</pre>
        </div>
      </p>
      <hr>
      <span>You are receiving this mail because:</span>
      
      <ul>
          <li>You are on the CC list for the bug.</li>
      </ul>
    </body>
</html>