Files
clang-p2996/polly/test/Isl/CodeGen/ptrtoint_as_parameter.ll
Roman Lebedev 81fc53a36a [SCEV] Introduce SCEVPtrToIntExpr (PR46786)
And use it to model LLVM IR's `ptrtoint` cast.

This is essentially an alternative to D88806, but with no chance for
all the problems it caused due to having the cast as implicit there.
(see rG7ee6c402474a2f5fd21c403e7529f97f6362fdb3)

As we've established by now, there are at least two reasons why we want this:
* It will allow SCEV to actually model the `ptrtoint` casts
  and their operands, instead of treating them as `SCEVUnknown`
* It should help with initial problem of PR46786 - this should eventually allow us
  to not loose pointer-ness of an expression in more cases

As discussed in [[ https://bugs.llvm.org/show_bug.cgi?id=46786 | PR46786 ]], in principle,
we could just extend `SCEVUnknown` with a `is ptrtoint` cast, because `ScalarEvolution::getPtrToIntExpr()`
should sink the cast as far down into the expression as possible,
so in the end we should always end up with `SCEVPtrToIntExpr` of `SCEVUnknown`.

But i think that it isn't the best solution, because it doesn't really matter
from memory consumption side - there probably won't be *that* many `SCEVPtrToIntExpr`s
for it to matter, and it allows for much better discoverability.

Reviewed By: mkazantsev

Differential Revision: https://reviews.llvm.org/D89456
2020-10-30 11:13:35 +03:00

40 lines
1.5 KiB
LLVM

; RUN: opt %loadPolly -polly-codegen -S < %s | FileCheck %s
;
; CHECK: if.then260:
; CHECK-NEXT: %p.4 = getelementptr inbounds i8, i8* null, i64 1
; CHECK-NEXT: %sub.ptr.lhs.cast263 = ptrtoint i8* %p.4 to i64
; CHECK-NEXT: %sub.ptr.sub265 = sub i64 %sub.ptr.lhs.cast263, 0
; CHECK-NEXT: %div = udiv i64 0, %sub.ptr.sub265
; CHECK-NEXT: %cmp268 = icmp ult i64 0, %div
; CHECK-NEXT: br i1 %cmp268, label %cond.true270, label %while.cond.region_exiting
;
target datalayout = "e-m:e-i64:64-f80:128-n8:16:32:64-S128"
; Function Attrs: nounwind uwtable
define void @XS_MIME__QuotedPrint_encode_qp() {
entry:
%Perl_sv_len = alloca i64, align 8
br label %if.end
if.end: ; preds = %entry
br label %while.cond
while.cond: ; preds = %cond.true270, %if.then260, %if.end
%p.0 = phi i8* [ null, %if.end ], [ %p.4, %if.then260 ], [ %p.4, %cond.true270 ]
br i1 undef, label %if.then260, label %while.body210
while.body210: ; preds = %while.cond
ret void
if.then260: ; preds = %while.cond
%p.4 = getelementptr inbounds i8, i8* null, i64 1
%sub.ptr.lhs.cast263 = ptrtoint i8* %p.4 to i64
%sub.ptr.sub265 = sub i64 %sub.ptr.lhs.cast263, 0
%div = udiv i64 0, %sub.ptr.sub265
%cmp268 = icmp ult i64 0, %div
br i1 %cmp268, label %cond.true270, label %while.cond
cond.true270: ; preds = %if.then260
br label %while.cond
}