From 6c8adc505471542be38bd71d1000062daa46d7bc Mon Sep 17 00:00:00 2001 From: Nikita Popov Date: Thu, 3 Mar 2022 10:49:00 +0100 Subject: [PATCH] [InstCombine] Remove unnecessary byval check in callee cast fold The logic for handling this was fixed in 8d7f118ab2b9e51d6cf2811291e319b4d977eb8c, but the check for byval on the callee was retained. This resulted in a weird situation where the transform would work depending on whether the byval was only on the call or on both the call and the function. --- llvm/lib/Transforms/InstCombine/InstCombineCalls.cpp | 3 +-- llvm/test/Transforms/InstCombine/byval.ll | 3 ++- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/llvm/lib/Transforms/InstCombine/InstCombineCalls.cpp b/llvm/lib/Transforms/InstCombine/InstCombineCalls.cpp index 216626f9ffe8..573a8db8479f 100644 --- a/llvm/lib/Transforms/InstCombine/InstCombineCalls.cpp +++ b/llvm/lib/Transforms/InstCombine/InstCombineCalls.cpp @@ -3142,8 +3142,7 @@ bool InstCombinerImpl::transformConstExprCastCall(CallBase &Call) { // // Similarly, avoid folding away bitcasts of byval calls. if (Callee->getAttributes().hasAttrSomewhere(Attribute::InAlloca) || - Callee->getAttributes().hasAttrSomewhere(Attribute::Preallocated) || - Callee->getAttributes().hasAttrSomewhere(Attribute::ByVal)) + Callee->getAttributes().hasAttrSomewhere(Attribute::Preallocated)) return false; auto AI = Call.arg_begin(); diff --git a/llvm/test/Transforms/InstCombine/byval.ll b/llvm/test/Transforms/InstCombine/byval.ll index b7459ef1fdf0..e62bbe21c806 100644 --- a/llvm/test/Transforms/InstCombine/byval.ll +++ b/llvm/test/Transforms/InstCombine/byval.ll @@ -18,7 +18,8 @@ define void @add_byval(i64* %in) { define void @add_byval_2(i64* %in) { ; CHECK-LABEL: @add_byval_2( -; CHECK-NEXT: call void bitcast (void (double*)* @add_byval_callee_2 to void (i64*)*)(i64* byval(i64) [[IN:%.*]]) +; CHECK-NEXT: [[TMP1:%.*]] = bitcast i64* [[IN:%.*]] to double* +; CHECK-NEXT: call void @add_byval_callee_2(double* byval(double) [[TMP1]]) ; CHECK-NEXT: ret void ; %tmp = bitcast void (double*)* @add_byval_callee_2 to void (i64*)*