llvm.org GIT mirror llvm / 4d04e9b
[InstSimplify] Constant fold the new GEP in SimplifyGEPInst. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@304784 91177308-0d34-0410-b5e6-96231b3b80d8 Joey Gouly 2 years ago
7 changed file(s) with 65 addition(s) and 8 deletion(s). Raw diff Collapse all Expand all
38833883 if (!all_of(Ops, [](Value *V) { return isa(V); }))
38843884 return nullptr;
38853885
3886 return ConstantExpr::getGetElementPtr(SrcTy, cast(Ops[0]),
3887 Ops.slice(1));
3886 auto *CE = ConstantExpr::getGetElementPtr(SrcTy, cast(Ops[0]),
3887 Ops.slice(1));
3888 if (auto *CEFolded = ConstantFoldConstant(CE, Q.DL))
3889 return CEFolded;
3890 return CE;
38883891 }
38893892
38903893 Value *llvm::SimplifyGEPInst(Type *SrcTy, ArrayRef Ops,
4343 %9 = add i32 %f.promoted, %smax
4444 %10 = add i32 %9, 2
4545 call void @llvm.memset.p0i8.i32(i8* %scevgep, i8 %conv6, i32 %10, i32 1, i1 false)
46 ; 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)
46 ; 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)
4747 ; 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)
4848 ret i32 0
4949 }
6868
6969 define i1 @PR31262() {
7070 ; CHECK-LABEL: @PR31262(
71 ; 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))
71 ; 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))
7272 ;
7373 %idx = getelementptr inbounds [1 x i32], [1 x i32]* @a, i64 0, i64 undef
7474 %cmp = icmp uge i32* %idx, getelementptr inbounds ([1 x i32], [1 x i32]* @a, i32 0, i32 0)
0 ; RUN: opt -always-inline -S %s | FileCheck %s
1 %0 = type { i64, i64, i8 addrspace(1)*, i8 addrspace(1)* }
2 %__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] }
3 %struct.__block_descriptor = type { i64, i64 }
4 %struct.__block_literal_generic = type { i8*, i32, i32, i8*, %struct.__block_descriptor addrspace(1)* }
5
6 @__aaa_struct_ptr = external addrspace(1) global %__aaa_struct
7 @__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" }
8
9 ; Function Attrs: alwaysinline norecurse nounwind readonly
10 define i32 @bl0_block_invoke(i8 addrspace(4)* nocapture readnone, i32 addrspace(1)* nocapture readonly) #0 {
11 entry:
12 %2 = load i32, i32 addrspace(1)* %1, align 4
13 %mul = shl nsw i32 %2, 1
14 ret i32 %mul
15 }
16
17 ; Function Attrs: alwaysinline nounwind
18 define i32 @f0(i32 addrspace(1)*, i32 (i32 addrspace(1)*) addrspace(4)*) #1 {
19 entry:
20 %block.literal = bitcast i32 (i32 addrspace(1)*) addrspace(4)* %1 to %struct.__block_literal_generic addrspace(4)*
21 %2 = getelementptr inbounds %struct.__block_literal_generic, %struct.__block_literal_generic addrspace(4)* %block.literal, i64 0, i32 3
22 %3 = bitcast i32 (i32 addrspace(1)*) addrspace(4)* %1 to i8 addrspace(4)*
23 %4 = bitcast i8* addrspace(4)* %2 to i32 (i8 addrspace(4)*, i32 addrspace(1)*)* addrspace(4)*
24 %5 = load i32 (i8 addrspace(4)*, i32 addrspace(1)*)*, i32 (i8 addrspace(4)*, i32 addrspace(1)*)* addrspace(4)* %4, align 8
25 %call = tail call i32 %5(i8 addrspace(4)* %3, i32 addrspace(1)* %0) #2
26 ret i32 %call
27 }
28
29 ; CHECK-LABEL: define void @f1
30 ; 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
31
32 ; Function Attrs: alwaysinline nounwind
33 define void @f1(i32 addrspace(1)*) #1 {
34 entry:
35 %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
36 store i32 %call, i32 addrspace(1)* %0, align 4
37 %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
38 store i32 %call1, i32 addrspace(1)* %0, align 4
39 ret void
40 }
41
42 ; Function Attrs: alwaysinline norecurse nounwind readonly
43 define i32 @__f1_block_invoke(i8 addrspace(4)* nocapture readnone, i32 addrspace(1)* nocapture readonly) #0 {
44 entry:
45 %2 = load i32, i32 addrspace(1)* %1, align 4
46 %add = add nsw i32 %2, 1
47 ret i32 %add
48 }
49
50 attributes #0 = { alwaysinline norecurse nounwind readonly }
51 attributes #1 = { alwaysinline nounwind }
52 attributes #2 = { nobuiltin nounwind }
53 attributes #3 = { nobuiltin }
5050 ret <4 x i8*> %gep
5151
5252 ; CHECK-LABEL: @test5
53 ; CHECK-NEXT: ret <4 x i8*> getelementptr (i8, <4 x i8*> , <4 x i32> 1>)
53 ; CHECK-NEXT: ret <4 x i8*> getelementptr (i8, <4 x i8*> , <4 x i64> 1>)
5454 }
5555
5656 @v = global [24 x [42 x [3 x i32]]] zeroinitializer, align 16
394394 ; CHECK: g:
395395 ; CHECK-NEXT: [[N:%.*]] = phi i32* [ [[H:%.*]], [[I:%.*]] ], [ null, [[B:%.*]] ]
396396 ; CHECK-NEXT: [[H]] = getelementptr i32, i32* [[N]], i64 1
397 ; CHECK-NEXT: [[J:%.*]] = icmp eq i32* [[H]], getelementptr (i32, i32* null, i64 8)
397 ; CHECK-NEXT: [[J:%.*]] = icmp eq i32* %h, inttoptr (i64 32 to i32*)
398398 ; CHECK-NEXT: br i1 [[J]], label [[C:%.*]], label [[I]]
399399 ; CHECK: i:
400400 ; CHECK-NEXT: br i1 undef, label [[K:%.*]], label [[G]]
88 ;; Test that we forward the first store to the second load
99 define i16 @bazinga() {
1010 ; CHECK-LABEL: @bazinga(
11 ; CHECK-NEXT: [[_TMP10:%.*]] = load i16, i16* getelementptr inbounds (%rec11, %rec11* @str, i16 0, i32 1)
12 ; CHECK-NEXT: store i16 [[_TMP10]], i16* getelementptr inbounds (%rec11, %rec11* @str, i16 0, i32 0)
11 ; CHECK-NEXT: [[_TMP10:%.*]] = load i16, i16* getelementptr inbounds (%rec11, %rec11* @str, i64 0, i32 1)
12 ; CHECK-NEXT: store i16 [[_TMP10]], i16* getelementptr inbounds (%rec11, %rec11* @str, i64 0, i32 0)
1313 ; CHECK-NEXT: [[_TMP15:%.*]] = icmp eq i16 [[_TMP10]], 3
1414 ; CHECK-NEXT: [[_TMP16:%.*]] = select i1 [[_TMP15]], i16 1, i16 0
1515 ; CHECK-NEXT: br label [[BB1:%.*]]