[llvm-bugs] [Bug 46757] New: loop-reduce introduce invnalid ptrtoint/inttoptr

via llvm-bugs llvm-bugs at lists.llvm.org
Thu Jul 16 21:02:23 PDT 2020


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

            Bug ID: 46757
           Summary: loop-reduce introduce invnalid ptrtoint/inttoptr
           Product: libraries
           Version: trunk
          Hardware: PC
                OS: Linux
            Status: NEW
          Severity: enhancement
          Priority: P
         Component: Loop Optimizer
          Assignee: unassignedbugs at nondot.org
          Reporter: yyc1992 at gmail.com
                CC: llvm-bugs at lists.llvm.org

Optimizing the code below with `opt -loop-reduce` causes incorrect `inttoptr`
to be emitted for the non-integral pointer.

```
target datalayout =
"e-m:e-p:32:32-Fi8-i64:64-v128:64:128-a:0:32-n32-S64-ni:10:11:12:13"
target triple = "armv7l-unknown-linux-gnueabihf"

define dso_local void @julia_roundup_19730() {
top:
  br label %L37

L37:                                              ; preds = %L49, %top
  %value_phi7 = phi i32 [ %3, %L49 ], [ 0, %top ]
  br i1 undef, label %L49, label %L47

L47:                                              ; preds = %L37
  unreachable

L49:                                              ; preds = %L37
  %0 = add i32 %value_phi7, -2
  %1 = getelementptr inbounds i8, i8 addrspace(13)* null, i32 %0
  %2 = load i8, i8 addrspace(13)* %1, align 1
  %3 = add i32 %value_phi7, -1
  br label %L37
}
```

The transformation done is,

```
*** IR Dump Before Loop Strength Reduction ***
; Preheader:
top:
  br label %L37

; Loop:
L37:                                              ; preds = %L49, %top
  %value_phi7 = phi i32 [ %3, %L49 ], [ 0, %top ]
  br i1 false, label %L49, label %L47

L49:                                              ; preds = %L37
  %0 = add i32 %value_phi7, -2
  %1 = getelementptr inbounds i8, i8 addrspace(13)* null, i32 %0
  %2 = load i8, i8 addrspace(13)* %1, align 1
  %3 = add i32 %value_phi7, -1
  br label %L37

; Exit blocks
L47:                                              ; preds = %L37
  unreachable
*** IR Dump After Loop Strength Reduction ***
; Preheader:
top:
  br label %L37

; Loop:
L37:                                              ; preds = %L49, %top
  %lsr.iv = phi i32 [ %lsr.iv.next, %L49 ], [ -2, %top ]
  %lsr.iv1 = inttoptr i32 %lsr.iv to i8 addrspace(13)*
  br i1 false, label %L49, label %L47

L49:                                              ; preds = %L37
  %0 = load i8, i8 addrspace(13)* %lsr.iv1, align 1
  %lsr.iv.next = add nsw i32 %lsr.iv, -1
  br label %L37

; Exit blocks
L47:                                              ; preds = %L37
  unreachable
```

Reproducible as of a week ago on master.

-- 
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/20200717/d1a2cd29/attachment.html>


More information about the llvm-bugs mailing list