Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions llvm/lib/Analysis/InstructionSimplify.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -671,12 +671,12 @@ Value *llvm::simplifyAddInst(Value *Op0, Value *Op1, bool IsNSW, bool IsNUW,
/// This is very similar to stripAndAccumulateConstantOffsets(), except it
/// normalizes the offset bitwidth to the stripped pointer type, not the
/// original pointer type.
static APInt stripAndComputeConstantOffsets(const DataLayout &DL, Value *&V,
bool AllowNonInbounds = false) {
static APInt stripAndComputeConstantOffsets(const DataLayout &DL, Value *&V) {
assert(V->getType()->isPtrOrPtrVectorTy());

APInt Offset = APInt::getZero(DL.getIndexTypeSizeInBits(V->getType()));
V = V->stripAndAccumulateConstantOffsets(DL, Offset, AllowNonInbounds);
V = V->stripAndAccumulateConstantOffsets(DL, Offset,
/*AllowNonInbounds=*/true);
// As that strip may trace through `addrspacecast`, need to sext or trunc
// the offset calculated.
return Offset.sextOrTrunc(DL.getIndexTypeSizeInBits(V->getType()));
Expand Down
6 changes: 1 addition & 5 deletions llvm/test/Transforms/InstSimplify/ptr_diff.ll
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,7 @@ define i64 @ptrdiff(ptr %ptr) {

define i64 @ptrdiff_no_inbounds(ptr %ptr) {
; CHECK-LABEL: @ptrdiff_no_inbounds(
; CHECK-NEXT: [[LAST:%.*]] = getelementptr i8, ptr [[PTR:%.*]], i32 42
; CHECK-NEXT: [[FIRST_INT:%.*]] = ptrtoint ptr [[PTR]] to i64
; CHECK-NEXT: [[LAST_INT:%.*]] = ptrtoint ptr [[LAST]] to i64
; CHECK-NEXT: [[DIFF:%.*]] = sub i64 [[LAST_INT]], [[FIRST_INT]]
; CHECK-NEXT: ret i64 [[DIFF]]
; CHECK-NEXT: ret i64 42
;
%last = getelementptr i8, ptr %ptr, i32 42
%first.int = ptrtoint ptr %ptr to i64
Expand Down
Loading