[LLVMbugs] [Bug 24059] New: LICM incorrectly preserves dereferenceability attributes

bugzilla-daemon at llvm.org bugzilla-daemon at llvm.org
Tue Jul 7 16:36:00 PDT 2015


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

            Bug ID: 24059
           Summary: LICM incorrectly preserves dereferenceability
                    attributes
           Product: libraries
           Version: trunk
          Hardware: PC
                OS: All
            Status: NEW
          Severity: normal
          Priority: P
         Component: Scalar Optimizations
          Assignee: unassignedbugs at nondot.org
          Reporter: sanjoy at playingwithpointers.com
                CC: llvmbugs at cs.uiuc.edu
    Classification: Unclassified

While this bug is easiest to demonstrate via LICM, it is a more
general issue.  Currently LLVM does not strip the !dereferenceable
(and other associated) attribute when hoisting instructions over
control flow.  This is problematic when the dereferencability of a
value is control dependent on the check LICM hoists the instruction
over.

For instance, running the following IR through -basicaa -licm moves
the load of %v_ptr to the loop's preheader while keeping the
!dereferencability intact, but it is possible %v_ptr is
dereferencability only if %cmp1 is true.

```
target datalayout = "e-m:e-i64:64-f80:128-n8:16:32:64-S128"
target triple = "x86_64-unknown-linux-gnu"

define void @test1(i32* noalias nocapture %a, i32* noalias nocapture readonly
%b, i32** nocapture readonly nonnull dereferenceable(16) %c, i32 %n) #0 {
entry:
  %cmp11 = icmp sgt i32 %n, 0
  br i1 %cmp11, label %for.body, label %for.end

for.body:                                         ; preds = %entry, %for.inc
  %indvars.iv = phi i64 [ %indvars.iv.next, %for.inc ], [ 0, %entry ]
  %arrayidx = getelementptr inbounds i32, i32* %a, i64 %indvars.iv
  %v0 = load i32, i32* %arrayidx, align 4
  %cmp1 = icmp sgt i32 %v0, 0
  br i1 %cmp1, label %if.then, label %for.inc

if.then:                                          ; preds = %for.body
  %v_ptr = load i32*, i32** %c, align 4, !dereferenceable !0
  %v1 = load i32, i32* %v_ptr, align 4
  %arrayidx3 = getelementptr inbounds i32, i32* %b, i64 %indvars.iv
  %v2 = load i32, i32* %arrayidx3, align 4
  %mul = mul nsw i32 %v2, %v1
  store i32 %mul, i32* %arrayidx, align 4
  br label %for.inc

for.inc:                                          ; preds = %for.body, %if.then
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
  %lftr.wideiv = trunc i64 %indvars.iv.next to i32
  %exitcond = icmp eq i32 %lftr.wideiv, %n
  br i1 %exitcond, label %for.end, label %for.body

for.end:                                          ; preds = %for.inc, %entry
  ret void
}

!0 = !{i64 4}
!1 = !{i64 2}
!2 = !{}
```

-- 
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/20150707/f018223d/attachment.html>


More information about the llvm-bugs mailing list