https://bugs.llvm.org/show_bug.cgi?id=44403
Bug ID: 44403
Summary: Folding 'gep p, (q - p)' to q should check it is never
used for loads & stores
Product: libraries
Version: trunk
Hardware: PC
OS: All
Status: NEW
Severity: normal
Priority: P
Component: Scalar Optimizations
Assignee: unassignedb...@nondot.org
Reporter: juneyoung....@sf.snu.ac.kr
CC: llvm-bugs@lists.llvm.org
```
$ cat gep.ll
define i8* @f(i8* %p, i8* %q) {
%i = ptrtoint i8* %p to i64
%j = ptrtoint i8* %q to i64
%diff = sub i64 %j, %i
%p2 = getelementptr i8, i8* %p, i64 %diff
ret i8* %p2
}
$ opt -instcombine gep.ll -S -o -
; ModuleID = 'gep.ll'
source_filename = "gep.ll"
define i8* @f(i8* %p, i8* %q) {
ret i8* %q
}
```
According to the GEP document:
https://llvm.org/docs/GetElementPtr.html#can-i-compute-the-distance-between-two-objects-and-add-that-value-to-one-address-to-compute-the-other-address
Replacing ‘gep p, (q - p)’ with q is invalid when it is used by memory access
operations.
InstCombine and InstSimplify both do this.
`llc gep.ll -o -` emits an optimized assembly, so SelDag or MIR seem to already
have optimizations for these this pattern if my understanding is correct?
--
You are receiving this mail because:
You are on the CC list for the bug.
_______________________________________________
llvm-bugs mailing list
llvm-bugs@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-bugs