mirror of
https://github.com/RPCS3/llvm-mirror.git
synced 2024-11-26 12:43:36 +01:00
[InstSimplify] Constant fold the new GEP in SimplifyGEPInst.
llvm-svn: 304784
This commit is contained in:
parent
77b6a5876a
commit
8f8710bf2b
@ -3884,8 +3884,11 @@ static Value *SimplifyGEPInst(Type *SrcTy, ArrayRef<Value *> Ops,
|
||||
if (!all_of(Ops, [](Value *V) { return isa<Constant>(V); }))
|
||||
return nullptr;
|
||||
|
||||
return ConstantExpr::getGetElementPtr(SrcTy, cast<Constant>(Ops[0]),
|
||||
Ops.slice(1));
|
||||
auto *CE = ConstantExpr::getGetElementPtr(SrcTy, cast<Constant>(Ops[0]),
|
||||
Ops.slice(1));
|
||||
if (auto *CEFolded = ConstantFoldConstant(CE, Q.DL))
|
||||
return CEFolded;
|
||||
return CE;
|
||||
}
|
||||
|
||||
Value *llvm::SimplifyGEPInst(Type *SrcTy, ArrayRef<Value *> Ops,
|
||||
|
@ -44,7 +44,7 @@ entry:
|
||||
%9 = add i32 %f.promoted, %smax
|
||||
%10 = add i32 %9, 2
|
||||
call void @llvm.memset.p0i8.i32(i8* %scevgep, i8 %conv6, i32 %10, i32 1, i1 false)
|
||||
; CHECK: call void @llvm.memset.p0i8.i32(i8* getelementptr inbounds ([6 x [6 x [7 x i8]]], [6 x [6 x [7 x i8]]]* @j, i32 0, i64 5, i64 4, i32 1), i8 %conv6, i32 1, i32 1, i1 false)
|
||||
; CHECK: call void @llvm.memset.p0i8.i32(i8* getelementptr inbounds ([6 x [6 x [7 x i8]]], [6 x [6 x [7 x i8]]]* @j, i32 0, i{{32|64}} 5, i{{32|64}} 4, i32 1), i8 %conv6, i32 1, i32 1, i1 false)
|
||||
; CHECK-NOT: call void @llvm.memset.p0i8.i32(i8* getelementptr ([6 x [6 x [7 x i8]]], [6 x [6 x [7 x i8]]]* @j, i64 1, i64 4, i64 4, i32 1)
|
||||
ret i32 0
|
||||
}
|
||||
|
@ -69,7 +69,7 @@ define i1 @gep4() {
|
||||
|
||||
define i1 @PR31262() {
|
||||
; CHECK-LABEL: @PR31262(
|
||||
; CHECK-NEXT: ret i1 icmp uge (i32* getelementptr ([1 x i32], [1 x i32]* @a, i64 0, i64 undef), i32* getelementptr inbounds ([1 x i32], [1 x i32]* @a, i32 0, i32 0))
|
||||
; CHECK-NEXT: ret i1 icmp uge (i32* getelementptr ([1 x i32], [1 x i32]* @a, i32 0, i32 undef), i32* getelementptr inbounds ([1 x i32], [1 x i32]* @a, i32 0, i32 0))
|
||||
;
|
||||
%idx = getelementptr inbounds [1 x i32], [1 x i32]* @a, i64 0, i64 undef
|
||||
%cmp = icmp uge i32* %idx, getelementptr inbounds ([1 x i32], [1 x i32]* @a, i32 0, i32 0)
|
||||
|
54
test/Transforms/InstSimplify/simplify-nested-bitcast.ll
Normal file
54
test/Transforms/InstSimplify/simplify-nested-bitcast.ll
Normal file
@ -0,0 +1,54 @@
|
||||
; RUN: opt -always-inline -S %s | FileCheck %s
|
||||
%0 = type { i64, i64, i8 addrspace(1)*, i8 addrspace(1)* }
|
||||
%__aaa_struct = type { { i8**, i32, i32, i8*, %struct.__block_descriptor addrspace(1)* }, %0, [17 x i8], { i8**, i32, i32, i8*, %struct.__block_descriptor addrspace(1)* }, %0, [18 x i8] }
|
||||
%struct.__block_descriptor = type { i64, i64 }
|
||||
%struct.__block_literal_generic = type { i8*, i32, i32, i8*, %struct.__block_descriptor addrspace(1)* }
|
||||
|
||||
@__aaa_struct_ptr = external addrspace(1) global %__aaa_struct
|
||||
@__aaa_const_init = constant %__aaa_struct { { i8**, i32, i32, i8*, %struct.__block_descriptor addrspace(1)* } { i8** null, i32 1342177280, i32 0, i8* bitcast (i32 (i8 addrspace(4)*, i32 addrspace(1)*)* @bl0_block_invoke to i8*), %struct.__block_descriptor addrspace(1)* bitcast (%0 addrspace(1)* getelementptr inbounds (%__aaa_struct, %__aaa_struct addrspace(1)* @__aaa_struct_ptr, i32 0, i32 1) to %struct.__block_descriptor addrspace(1)*) }, %0 { i64 0, i64 32, i8 addrspace(1)* getelementptr inbounds (%__aaa_struct, %__aaa_struct addrspace(1)* @__aaa_struct_ptr, i32 0, i32 2, i32 0), i8 addrspace(1)* null }, [17 x i8] c"bl0_block_invoke\00", { i8**, i32, i32, i8*, %struct.__block_descriptor addrspace(1)* } { i8** null, i32 1342177280, i32 0, i8* bitcast (i32 (i8 addrspace(4)*, i32 addrspace(1)*)* @__f1_block_invoke to i8*), %struct.__block_descriptor addrspace(1)* bitcast (%0 addrspace(1)* getelementptr inbounds (%__aaa_struct, %__aaa_struct addrspace(1)* @__aaa_struct_ptr, i32 0, i32 4) to %struct.__block_descriptor addrspace(1)*) }, %0 { i64 0, i64 32, i8 addrspace(1)* getelementptr inbounds (%__aaa_struct, %__aaa_struct addrspace(1)* @__aaa_struct_ptr, i32 0, i32 5, i32 0), i8 addrspace(1)* null }, [18 x i8] c"__f1_block_invoke\00" }
|
||||
|
||||
; Function Attrs: alwaysinline norecurse nounwind readonly
|
||||
define i32 @bl0_block_invoke(i8 addrspace(4)* nocapture readnone, i32 addrspace(1)* nocapture readonly) #0 {
|
||||
entry:
|
||||
%2 = load i32, i32 addrspace(1)* %1, align 4
|
||||
%mul = shl nsw i32 %2, 1
|
||||
ret i32 %mul
|
||||
}
|
||||
|
||||
; Function Attrs: alwaysinline nounwind
|
||||
define i32 @f0(i32 addrspace(1)*, i32 (i32 addrspace(1)*) addrspace(4)*) #1 {
|
||||
entry:
|
||||
%block.literal = bitcast i32 (i32 addrspace(1)*) addrspace(4)* %1 to %struct.__block_literal_generic addrspace(4)*
|
||||
%2 = getelementptr inbounds %struct.__block_literal_generic, %struct.__block_literal_generic addrspace(4)* %block.literal, i64 0, i32 3
|
||||
%3 = bitcast i32 (i32 addrspace(1)*) addrspace(4)* %1 to i8 addrspace(4)*
|
||||
%4 = bitcast i8* addrspace(4)* %2 to i32 (i8 addrspace(4)*, i32 addrspace(1)*)* addrspace(4)*
|
||||
%5 = load i32 (i8 addrspace(4)*, i32 addrspace(1)*)*, i32 (i8 addrspace(4)*, i32 addrspace(1)*)* addrspace(4)* %4, align 8
|
||||
%call = tail call i32 %5(i8 addrspace(4)* %3, i32 addrspace(1)* %0) #2
|
||||
ret i32 %call
|
||||
}
|
||||
|
||||
; CHECK-LABEL: define void @f1
|
||||
; CHECK: %1 = load i32 (i8 addrspace(4)*, i32 addrspace(1)*)*, i32 (i8 addrspace(4)*, i32 addrspace(1)*)* addrspace(4)* bitcast (i8* addrspace(4)* getelementptr (%__aaa_struct, %__aaa_struct addrspace(4)* addrspacecast (%__aaa_struct addrspace(1)* @__aaa_struct_ptr to %__aaa_struct addrspace(4)*), i64 0, i32 0, i32 3) to i32 (i8 addrspace(4)*, i32 addrspace(1)*)* addrspace(4)*), align 8
|
||||
|
||||
; Function Attrs: alwaysinline nounwind
|
||||
define void @f1(i32 addrspace(1)*) #1 {
|
||||
entry:
|
||||
%call = tail call i32 @f0(i32 addrspace(1)* %0, i32 (i32 addrspace(1)*) addrspace(4)* addrspacecast (i32 (i32 addrspace(1)*) addrspace(1)* bitcast (%__aaa_struct addrspace(1)* @__aaa_struct_ptr to i32 (i32 addrspace(1)*) addrspace(1)*) to i32 (i32 addrspace(1)*) addrspace(4)*)) #3
|
||||
store i32 %call, i32 addrspace(1)* %0, align 4
|
||||
%call1 = tail call i32 @f0(i32 addrspace(1)* %0, i32 (i32 addrspace(1)*) addrspace(4)* addrspacecast (i32 (i32 addrspace(1)*) addrspace(1)* bitcast ({ i8**, i32, i32, i8*, %struct.__block_descriptor addrspace(1)* } addrspace(1)* getelementptr inbounds (%__aaa_struct, %__aaa_struct addrspace(1)* @__aaa_struct_ptr, i32 0, i32 3) to i32 (i32 addrspace(1)*) addrspace(1)*) to i32 (i32 addrspace(1)*) addrspace(4)*)) #3
|
||||
store i32 %call1, i32 addrspace(1)* %0, align 4
|
||||
ret void
|
||||
}
|
||||
|
||||
; Function Attrs: alwaysinline norecurse nounwind readonly
|
||||
define i32 @__f1_block_invoke(i8 addrspace(4)* nocapture readnone, i32 addrspace(1)* nocapture readonly) #0 {
|
||||
entry:
|
||||
%2 = load i32, i32 addrspace(1)* %1, align 4
|
||||
%add = add nsw i32 %2, 1
|
||||
ret i32 %add
|
||||
}
|
||||
|
||||
attributes #0 = { alwaysinline norecurse nounwind readonly }
|
||||
attributes #1 = { alwaysinline nounwind }
|
||||
attributes #2 = { nobuiltin nounwind }
|
||||
attributes #3 = { nobuiltin }
|
@ -51,7 +51,7 @@ define <4 x i8*> @test5() {
|
||||
ret <4 x i8*> %gep
|
||||
|
||||
; CHECK-LABEL: @test5
|
||||
; CHECK-NEXT: ret <4 x i8*> getelementptr (i8, <4 x i8*> <i8* inttoptr (i64 1 to i8*), i8* inttoptr (i64 2 to i8*), i8* inttoptr (i64 3 to i8*), i8* inttoptr (i64 4 to i8*)>, <4 x i32> <i32 1, i32 1, i32 1, i32 1>)
|
||||
; CHECK-NEXT: ret <4 x i8*> getelementptr (i8, <4 x i8*> <i8* inttoptr (i64 1 to i8*), i8* inttoptr (i64 2 to i8*), i8* inttoptr (i64 3 to i8*), i8* inttoptr (i64 4 to i8*)>, <4 x i64> <i64 1, i64 1, i64 1, i64 1>)
|
||||
}
|
||||
|
||||
@v = global [24 x [42 x [3 x i32]]] zeroinitializer, align 16
|
||||
|
@ -395,7 +395,7 @@ define void @test10() {
|
||||
; CHECK: g:
|
||||
; CHECK-NEXT: [[N:%.*]] = phi i32* [ [[H:%.*]], [[I:%.*]] ], [ null, [[B:%.*]] ]
|
||||
; CHECK-NEXT: [[H]] = getelementptr i32, i32* [[N]], i64 1
|
||||
; CHECK-NEXT: [[J:%.*]] = icmp eq i32* [[H]], getelementptr (i32, i32* null, i64 8)
|
||||
; CHECK-NEXT: [[J:%.*]] = icmp eq i32* %h, inttoptr (i64 32 to i32*)
|
||||
; CHECK-NEXT: br i1 [[J]], label [[C:%.*]], label [[I]]
|
||||
; CHECK: i:
|
||||
; CHECK-NEXT: br i1 undef, label [[K:%.*]], label [[G]]
|
||||
|
@ -9,8 +9,8 @@ target datalayout = "e-m:e-i64:64-f80:128-n8:16:32:64-S128"
|
||||
;; Test that we forward the first store to the second load
|
||||
define i16 @bazinga() {
|
||||
; CHECK-LABEL: @bazinga(
|
||||
; CHECK-NEXT: [[_TMP10:%.*]] = load i16, i16* getelementptr inbounds (%rec11, %rec11* @str, i16 0, i32 1)
|
||||
; CHECK-NEXT: store i16 [[_TMP10]], i16* getelementptr inbounds (%rec11, %rec11* @str, i16 0, i32 0)
|
||||
; CHECK-NEXT: [[_TMP10:%.*]] = load i16, i16* getelementptr inbounds (%rec11, %rec11* @str, i64 0, i32 1)
|
||||
; CHECK-NEXT: store i16 [[_TMP10]], i16* getelementptr inbounds (%rec11, %rec11* @str, i64 0, i32 0)
|
||||
; CHECK-NEXT: [[_TMP15:%.*]] = icmp eq i16 [[_TMP10]], 3
|
||||
; CHECK-NEXT: [[_TMP16:%.*]] = select i1 [[_TMP15]], i16 1, i16 0
|
||||
; CHECK-NEXT: br label [[BB1:%.*]]
|
||||
|
Loading…
Reference in New Issue
Block a user