From 9c2d1787076b5f7eb9f0d22a02cc904a40d4fa98 Mon Sep 17 00:00:00 2001 From: David Majnemer Date: Wed, 11 Mar 2015 18:03:05 +0000 Subject: [PATCH] InstCombine: Don't fold call bitcast into args if callee is byval This fixes a bug reported here: http://lists.cs.uiuc.edu/pipermail/llvm-commits/Week-of-Mon-20150309/265341.html git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@231948 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/Transforms/InstCombine/InstCombineCalls.cpp | 5 ++++- test/Transforms/InstCombine/call-cast-target.ll | 15 +++++++++++++++ 2 files changed, 19 insertions(+), 1 deletion(-) diff --git a/lib/Transforms/InstCombine/InstCombineCalls.cpp b/lib/Transforms/InstCombine/InstCombineCalls.cpp index a32ccabe4a7..00d92c873bd 100644 --- a/lib/Transforms/InstCombine/InstCombineCalls.cpp +++ b/lib/Transforms/InstCombine/InstCombineCalls.cpp @@ -1485,7 +1485,10 @@ bool InstCombiner::transformConstExprCastCall(CallSite CS) { // // into: // call void @takes_i32_inalloca(i32* null) - if (Callee->getAttributes().hasAttrSomewhere(Attribute::InAlloca)) + // + // Similarly, avoid folding away bitcasts of byval calls. + if (Callee->getAttributes().hasAttrSomewhere(Attribute::InAlloca) || + Callee->getAttributes().hasAttrSomewhere(Attribute::ByVal)) return false; CallSite::arg_iterator AI = CS.arg_begin(); diff --git a/test/Transforms/InstCombine/call-cast-target.ll b/test/Transforms/InstCombine/call-cast-target.ll index 4a5c94961e2..881e80762ea 100644 --- a/test/Transforms/InstCombine/call-cast-target.ll +++ b/test/Transforms/InstCombine/call-cast-target.ll @@ -72,3 +72,18 @@ entry: %call = tail call i32 bitcast (i32 (i32)* @fn4 to i32 (i32*)*)(i32* %a) ret i32 %call } + +declare i1 @fn5({ i32, i32 }* byval align 4 %r) + +define i1 @test5() { +; CHECK-LABEL: @test5 +; CHECK: %[[call:.*]] = call i1 bitcast (i1 ({ i32, i32 }*)* @fn5 to i1 (i32, i32)*)(i32 {{.*}}, i32 {{.*}}) +; CHECK-NEXT: ret i1 %[[call]] + %1 = alloca { i32, i32 }, align 4 + %2 = getelementptr inbounds { i32, i32 }, { i32, i32 }* %1, i32 0, i32 0 + %3 = load i32, i32* %2, align 4 + %4 = getelementptr inbounds { i32, i32 }, { i32, i32 }* %1, i32 0, i32 1 + %5 = load i32, i32* %4, align 4 + %6 = call i1 bitcast (i1 ({ i32, i32 }*)* @fn5 to i1 (i32, i32)*)(i32 %3, i32 %5) + ret i1 %6 +} -- 2.40.0