[llvm-bugs] [Bug 37005] New: [InstCombine] Incorrect reassociation of loop invariant vector GEP

via llvm-bugs llvm-bugs at lists.llvm.org
Wed Apr 4 11:52:03 PDT 2018


https://bugs.llvm.org/show_bug.cgi?id=37005

            Bug ID: 37005
           Summary: [InstCombine] Incorrect reassociation of loop
                    invariant vector GEP
           Product: new-bugs
           Version: trunk
          Hardware: PC
                OS: All
            Status: NEW
          Severity: enhancement
          Priority: P
         Component: new bugs
          Assignee: unassignedbugs at nondot.org
          Reporter: dneilson at azul.com
                CC: llvm-bugs at lists.llvm.org

A recent change can produce incorrect IR when presented with vector GEPs.

Offending change:

commit 0c137c5660209ecc1bc487b7f88774405d5cd7cb
Author: Sebastian Pop <sebpop at gmail.com>
Date:   Mon Mar 26 16:19:31 2018 +0000

    [InstCombine] reassociate loop invariant GEP chains to enable LICM

------

Test case -- gep.ll:
declare void @blackhole(<2 x i8*>)

define void @foo(i8* %base, i8** %in) {
entry:
  br label %loop

loop:
  %e1 = getelementptr inbounds i8*, i8** %in, i64 undef
  %e2 = getelementptr inbounds i8*, i8** %e1, i64 6
  %bc1 = bitcast i8** %e2 to <2 x i8*>*
  %e3 = getelementptr inbounds <2 x i8*>, <2 x i8*>* %bc1, i64 0, i64 0
  %e4 = getelementptr inbounds i8*, i8** %e3, <2 x i64> <i64 0, i64 1>  
  %pi1 = ptrtoint <2 x i8**> %e4 to <2 x i64>
  %lr1 = lshr <2 x i64> %pi1, <i64 21, i64 21>
  %sl1 = shl nuw nsw <2 x i64> %lr1, <i64 7, i64 7>
  %e5 = getelementptr inbounds i8, i8* %base, <2 x i64> %sl1
  %e6 = getelementptr inbounds i8, <2 x i8*> %e5, i64 80
  call void @blackhole(<2 x i8*> %e6)
  br label %loop
}

------

Run with: opt -instcombine -S gep.ll

------

Produces:
declare void @blackhole(<2 x i8*>)

define void @foo(i8* %base, i8** %in) {
entry:
  br label %loop

loop:                                             ; preds = %loop, %entry
  %e2 = getelementptr inbounds i8*, i8** %in, i64 undef
  %e4 = getelementptr inbounds i8*, i8** %e2, <2 x i64> <i64 0, i64 1>
  %pi1 = ptrtoint <2 x i8**> %e4 to <2 x i64>
  %lr1 = lshr <2 x i64> %pi1, <i64 21, i64 21>
  %sl1 = shl nuw nsw <2 x i64> %lr1, <i64 7, i64 7>
  %e5 = getelementptr inbounds i8, i8* %base, i64 80
  %e6 = getelementptr inbounds i8, <2 x i8*> %e5, <2 x i64> %sl1
  call void @blackhole(<2 x i8*> %e6)
  br label %loop
}

----

The change in question swaps the index operands of GEP %e5 and %e6. However,
the resulting %e5 is accidentally changed from a vector type to a scalar type.

-- 
You are receiving this mail because:
You are on the CC list for the bug.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-bugs/attachments/20180404/a06a1687/attachment.html>


More information about the llvm-bugs mailing list