mirror of
https://github.com/c64scene-ar/llvm-6502.git
synced 2025-01-14 00:32:55 +00:00
Fix creating bitcasts between address spaces in SCEV.
The test before wasn't successfully testing this since it was missing the datalayout piece to change the size of the second address space. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@193102 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
parent
325ee6e115
commit
4784bb6f44
@ -5103,18 +5103,23 @@ static Constant *BuildConstantFromSCEV(const SCEV *V) {
|
|||||||
case scAddExpr: {
|
case scAddExpr: {
|
||||||
const SCEVAddExpr *SA = cast<SCEVAddExpr>(V);
|
const SCEVAddExpr *SA = cast<SCEVAddExpr>(V);
|
||||||
if (Constant *C = BuildConstantFromSCEV(SA->getOperand(0))) {
|
if (Constant *C = BuildConstantFromSCEV(SA->getOperand(0))) {
|
||||||
if (C->getType()->isPointerTy())
|
if (PointerType *PTy = dyn_cast<PointerType>(C->getType())) {
|
||||||
C = ConstantExpr::getBitCast(C, Type::getInt8PtrTy(C->getContext()));
|
unsigned AS = PTy->getAddressSpace();
|
||||||
|
Type *DestPtrTy = Type::getInt8PtrTy(C->getContext(), AS);
|
||||||
|
C = ConstantExpr::getBitCast(C, DestPtrTy);
|
||||||
|
}
|
||||||
for (unsigned i = 1, e = SA->getNumOperands(); i != e; ++i) {
|
for (unsigned i = 1, e = SA->getNumOperands(); i != e; ++i) {
|
||||||
Constant *C2 = BuildConstantFromSCEV(SA->getOperand(i));
|
Constant *C2 = BuildConstantFromSCEV(SA->getOperand(i));
|
||||||
if (!C2) return 0;
|
if (!C2) return 0;
|
||||||
|
|
||||||
// First pointer!
|
// First pointer!
|
||||||
if (!C->getType()->isPointerTy() && C2->getType()->isPointerTy()) {
|
if (!C->getType()->isPointerTy() && C2->getType()->isPointerTy()) {
|
||||||
|
unsigned AS = C2->getType()->getPointerAddressSpace();
|
||||||
std::swap(C, C2);
|
std::swap(C, C2);
|
||||||
|
Type *DestPtrTy = Type::getInt8PtrTy(C->getContext(), AS);
|
||||||
// The offsets have been converted to bytes. We can add bytes to an
|
// The offsets have been converted to bytes. We can add bytes to an
|
||||||
// i8* by GEP with the byte count in the first index.
|
// i8* by GEP with the byte count in the first index.
|
||||||
C = ConstantExpr::getBitCast(C,Type::getInt8PtrTy(C->getContext()));
|
C = ConstantExpr::getBitCast(C, DestPtrTy);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Don't bother trying to sum two pointers. We probably can't
|
// Don't bother trying to sum two pointers. We probably can't
|
||||||
@ -5122,8 +5127,8 @@ static Constant *BuildConstantFromSCEV(const SCEV *V) {
|
|||||||
if (C2->getType()->isPointerTy())
|
if (C2->getType()->isPointerTy())
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
if (C->getType()->isPointerTy()) {
|
if (PointerType *PTy = dyn_cast<PointerType>(C->getType())) {
|
||||||
if (cast<PointerType>(C->getType())->getElementType()->isStructTy())
|
if (PTy->getElementType()->isStructTy())
|
||||||
C2 = ConstantExpr::getIntegerCast(
|
C2 = ConstantExpr::getIntegerCast(
|
||||||
C2, Type::getInt32Ty(C->getContext()), true);
|
C2, Type::getInt32Ty(C->getContext()), true);
|
||||||
C = ConstantExpr::getGetElementPtr(C, C2);
|
C = ConstantExpr::getGetElementPtr(C, C2);
|
||||||
|
@ -1,9 +1,11 @@
|
|||||||
; RUN: opt < %s -analyze -scalar-evolution | FileCheck %s
|
; RUN: opt < %s -analyze -scalar-evolution | FileCheck %s
|
||||||
|
|
||||||
target datalayout = "e-p:64:64:64-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:64:64-f32:32:32-f64:64:64-v64:64:64-v128:128:128-a0:0:64-s0:64:64-f80:128:128-n8:16:32:64-S128"
|
target datalayout = "e-p:64:64:64-p1:16:16:16-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:64:64-f32:32:32-f64:64:64-v64:64:64-v128:128:128-a0:0:64-s0:64:64-f80:128:128-n8:16:32:64-S128"
|
||||||
target triple = "x86_64-unknown-linux-gnu"
|
target triple = "x86_64-unknown-linux-gnu"
|
||||||
|
|
||||||
@foo.a = internal constant [8 x i32] [i32 0, i32 1, i32 2, i32 3, i32 4, i32 5, i32 6, i32 7], align 16
|
@foo.a = internal constant [8 x i32] [i32 0, i32 1, i32 2, i32 3, i32 4, i32 5, i32 6, i32 7], align 16
|
||||||
|
@foo.a_as1 = internal addrspace(1) constant [8 x i32] [i32 0, i32 1, i32 2, i32 3, i32 4, i32 5, i32 6, i32 7], align 16
|
||||||
|
|
||||||
|
|
||||||
define i32 @foo() nounwind uwtable noinline {
|
define i32 @foo() nounwind uwtable noinline {
|
||||||
entry:
|
entry:
|
||||||
@ -27,3 +29,27 @@ for.inc: ; preds = %for.cond
|
|||||||
for.end: ; preds = %for.cond
|
for.end: ; preds = %for.cond
|
||||||
ret i32 %sum.0
|
ret i32 %sum.0
|
||||||
}
|
}
|
||||||
|
|
||||||
|
define i32 @foo_as1() nounwind uwtable noinline {
|
||||||
|
entry:
|
||||||
|
br label %for.cond
|
||||||
|
|
||||||
|
for.cond: ; preds = %for.inc, %entry
|
||||||
|
%sum.0 = phi i32 [ 0, %entry ], [ %add, %for.inc ]
|
||||||
|
; CHECK: --> %sum.0 Exits: 28
|
||||||
|
%i.0 = phi i32 [ 0, %entry ], [ %inc, %for.inc ]
|
||||||
|
%cmp = icmp ult i32 %i.0, 8
|
||||||
|
br i1 %cmp, label %for.inc, label %for.end
|
||||||
|
|
||||||
|
for.inc: ; preds = %for.cond
|
||||||
|
%idxprom = sext i32 %i.0 to i64
|
||||||
|
%arrayidx = getelementptr inbounds [8 x i32] addrspace(1)* @foo.a_as1, i64 0, i64 %idxprom
|
||||||
|
%0 = load i32 addrspace(1)* %arrayidx, align 4
|
||||||
|
%add = add nsw i32 %sum.0, %0
|
||||||
|
%inc = add nsw i32 %i.0, 1
|
||||||
|
br label %for.cond
|
||||||
|
|
||||||
|
for.end: ; preds = %for.cond
|
||||||
|
ret i32 %sum.0
|
||||||
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user