Index: lib/Analysis/InstructionSimplify.cpp =================================================================== --- lib/Analysis/InstructionSimplify.cpp +++ lib/Analysis/InstructionSimplify.cpp @@ -4467,10 +4467,12 @@ const DominatorTree *DT, AssumptionCache *AC, OptimizationRemarkEmitter *ORE) { Value *Result; + if (auto *C = ConstantFoldInstruction(I, DL, TLI)) + return C; switch (I->getOpcode()) { default: - Result = ConstantFoldInstruction(I, DL, TLI); + Result = nullptr; break; case Instruction::FAdd: Result = SimplifyFAddInst(I->getOperand(0), I->getOperand(1), Index: test/Analysis/ConstantFolding/gep-constanfolding-error.ll =================================================================== --- test/Analysis/ConstantFolding/gep-constanfolding-error.ll +++ test/Analysis/ConstantFolding/gep-constanfolding-error.ll @@ -44,7 +44,7 @@ %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 } Index: test/Transforms/GVN/PRE/2011-06-01-NonLocalMemdepMiscompile.ll =================================================================== --- test/Transforms/GVN/PRE/2011-06-01-NonLocalMemdepMiscompile.ll +++ test/Transforms/GVN/PRE/2011-06-01-NonLocalMemdepMiscompile.ll @@ -19,7 +19,7 @@ br i1 undef, label %bb3, label %bb15 ; CHECK: bb1: -; CHECK: [[TMP:%.*]] = phi i8* [ getelementptr (i8, i8* null, i64 undef), %bb10 ], [ null, %bb ] +; CHECK: [[TMP:%.*]] = phi i8* [ getelementptr inbounds (i8, i8* null, i64 undef), %bb10 ], [ null, %bb ] ; CHECK: bb1.bb15_crit_edge: ; CHECK: %tmp17.pre = load i8, i8* [[TMP]], align 1 Index: test/Transforms/InstSimplify/compare.ll =================================================================== --- test/Transforms/InstSimplify/compare.ll +++ test/Transforms/InstSimplify/compare.ll @@ -69,7 +69,7 @@ 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) Index: test/Transforms/InstSimplify/simplify-nested-bitcast.ll =================================================================== --- /dev/null +++ test/Transforms/InstSimplify/simplify-nested-bitcast.ll @@ -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 inbounds (%__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 } Index: test/Transforms/InstSimplify/vector_gep.ll =================================================================== --- test/Transforms/InstSimplify/vector_gep.ll +++ test/Transforms/InstSimplify/vector_gep.ll @@ -51,7 +51,7 @@ ret <4 x i8*> %gep ; CHECK-LABEL: @test5 -; CHECK-NEXT: ret <4 x i8*> getelementptr (i8, <4 x i8*> , <4 x i32> ) +; CHECK-NEXT: ret <4 x i8*> getelementptr (i8, <4 x i8*> , <4 x i64> ) } @v = global [24 x [42 x [3 x i32]]] zeroinitializer, align 16 @@ -61,4 +61,4 @@ ; CHECK-NEXT: ret <16 x i32*> getelementptr ([24 x [42 x [3 x i32]]], [24 x [42 x [3 x i32]]]* @v, <16 x i64> zeroinitializer, <16 x i64> zeroinitializer, <16 x i64> , <16 x i64> zeroinitializer) %VectorGep = getelementptr [24 x [42 x [3 x i32]]], [24 x [42 x [3 x i32]]]* @v, i64 0, i64 0, <16 x i64> , i64 0 ret <16 x i32*> %VectorGep -} \ No newline at end of file +}