[llvm-bugs] [Bug 52429] New: InstSimplify incorrectly folds signed comparisons of 'gep inbounds'

via llvm-bugs llvm-bugs at lists.llvm.org
Fri Nov 5 16:14:58 PDT 2021


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

            Bug ID: 52429
           Summary: InstSimplify incorrectly folds signed comparisons of
                    'gep inbounds'
           Product: libraries
           Version: trunk
          Hardware: All
                OS: All
            Status: NEW
          Keywords: miscompilation
          Severity: normal
          Priority: P
         Component: Scalar Optimizations
          Assignee: unassignedbugs at nondot.org
          Reporter: nunoplopes at sapo.pt
                CC: lebedev.ri at gmail.com, llvm-bugs at lists.llvm.org,
                    regehr at cs.utah.edu, sanjoy at playingwithpointers.com

File: Transforms/InstSimplify/compare.ll

define i1 @gep_same_base_constant_indices(i8* %a) {
; CHECK-NEXT:    ret i1 true
;
  %arrayidx1 = getelementptr inbounds i8, i8* %a, i64 1
  %arrayidx2 = getelementptr inbounds i8, i8* %a, i64 10
  %cmp = icmp slt i8* %arrayidx1, %arrayidx2
  ret i1 %cmp
}

Folding such unsigned comparisons is correct, but not for signed as an object
may cross the unsigned/signed line, e.g:
ptr = malloc(42) // 0x7fff..ff0
ptr + 42  // 0x8....

-- 
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/20211105/256d5b0d/attachment.html>


More information about the llvm-bugs mailing list