LLVM Bugzilla is read-only and represents the historical archive of all LLVM issues filled before November 26, 2021. Use github to submit LLVM bugs

Bug 52429 - InstSimplify incorrectly folds signed comparisons of 'gep inbounds'
Summary: InstSimplify incorrectly folds signed comparisons of 'gep inbounds'
Status: RESOLVED FIXED
Alias: None
Product: libraries
Classification: Unclassified
Component: Scalar Optimizations (show other bugs)
Version: trunk
Hardware: All All
: P normal
Assignee: Unassigned LLVM Bugs
URL:
Keywords: miscompilation
Depends on:
Blocks:
 
Reported: 2021-11-05 16:14 PDT by Nuno Lopes
Modified: 2021-11-06 20:12 PDT (History)
7 users (show)

See Also:
Fixed By Commit(s): e3cec17b2db292227a2b92d46e653372dad711af


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Nuno Lopes 2021-11-05 16:14:58 PDT
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....
Comment 1 Nikita Popov 2021-11-06 04:59:20 PDT
https://reviews.llvm.org/D113343