Hi All, This patch is for PR1582. As recent discuss on that pr, the C++ FE doesn't track the restrict qualifier in the function declaration at all. When llvm-gcc handling CALL_EXPR and emiting callInst instruction, it can't get the "NoAlias" attribute, and hence insert a BitCast in CallInst. This patch is to eliminate this bitcast.
Testcase attached here also.
Index: llvm-convert.cpp =================================================================== --- llvm-convert.cpp (revision 43895) +++ llvm-convert.cpp (working copy) @@ -2846,8 +2846,16 @@ // to: // %tmp = call float @foo( ) // This commonly occurs due to C "implicit ..." semantics. + // + // Or + // + // call void bitcast (void (i32* noalias)* @foo to void (i32*)*)(i32* %x) + // to: + // call void @foo(i32* %x noalias) + // This occurs due to C++ FE doesn't track the restrict qualifier + // in the function declaration at all. if (ConstantExpr *CE = dyn_cast<ConstantExpr>(Callee)) { - if (CallOperands.empty() && CE->getOpcode() == Instruction::BitCast) { + if (CE->getOpcode() == Instruction::BitCast) { Constant *RealCallee = CE->getOperand(0); assert(isa<PointerType>(RealCallee->getType()) && "Bitcast to ptr not from ptr?"); @@ -2858,8 +2866,20 @@ const FunctionType *ActualFT = cast<FunctionType>(ActualPT->getElementType()); if (RealFT->getReturnType() == ActualFT->getReturnType() && - ActualFT->getNumParams() == 0) + ActualFT->getNumParams() == 0 && CallOperands.empty()) Callee = RealCallee; + else if (RealFT->getReturnType() == ActualFT->getReturnType() && + RealFT->getNumParams() == ActualFT->getNumParams() && + RealFT->getNumParams() == CallOperands.size()) { + bool isSame = true; + for (unsigned i = 0; i < RealFT->getNumParams(); ++i) + if (RealFT->getParamType(i) != ActualFT->getParamType(i)) { + isSame = false; + break; + } + if (isSame) + Callee = RealCallee; + } } } }
// RUN: %llvmgxx -c -emit-llvm %s -o - | llvm-dis | grep call | not grep bitcast void foo(int * __restrict myptr1, int * myptr2) { myptr1[0] = 0; myptr2[0] = 0; } int main() { int x, y; foo(&x, &y); return 0; }
_______________________________________________ llvm-commits mailing list llvm-commits@cs.uiuc.edu http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits