Index: lib/Transforms/Scalar/PartiallyInlineLibCalls.cpp =================================================================== --- lib/Transforms/Scalar/PartiallyInlineLibCalls.cpp +++ lib/Transforms/Scalar/PartiallyInlineLibCalls.cpp @@ -64,6 +64,7 @@ // Add attribute "readnone" so that backend can use a native sqrt instruction // for this call. Insert a FP compare instruction and a conditional branch // at the end of CurrBB. + Call->removeAttribute(AttributeList::FunctionIndex, Attribute::WriteOnly); Call->addAttribute(AttributeList::FunctionIndex, Attribute::ReadNone); CurrBB.getTerminator()->eraseFromParent(); Builder.SetInsertPoint(&CurrBB); Index: test/Transforms/PartiallyInlineLibCalls/X86/good-prototype.ll =================================================================== --- test/Transforms/PartiallyInlineLibCalls/X86/good-prototype.ll +++ test/Transforms/PartiallyInlineLibCalls/X86/good-prototype.ll @@ -5,7 +5,7 @@ define float @f(float %val) { ; CHECK-LABEL: @f( ; CHECK-NEXT: entry: -; CHECK-NEXT: [[RES:%.*]] = tail call float @sqrtf(float [[VAL:%.*]]) #0 +; CHECK-NEXT: [[RES:%.*]] = tail call float @sqrtf(float [[VAL:%.*]]) [[RN:#[0-9]+]] ; CHECK-NEXT: [[TMP0:%.*]] = fcmp oge float [[VAL]], 0.000000e+00 ; CHECK-NEXT: br i1 [[TMP0]], label [[ENTRY_SPLIT:%.*]], label [[CALL_SQRT:%.*]] ; CHECK: call.sqrt: @@ -20,4 +20,26 @@ ret float %res } +define float @f2(float %val) { +; CHECK-LABEL: @f2( +; CHECK-NEXT: entry: +; CHECK-NEXT: [[RES:%.*]] = tail call float @sqrtf(float [[VAL:%.*]]) [[RN]] +; CHECK-NEXT: [[TMP0:%.*]] = fcmp oge float [[VAL]], 0.000000e+00 +; CHECK-NEXT: br i1 [[TMP0]], label [[ENTRY_SPLIT:%.*]], label [[CALL_SQRT:%.*]] +; CHECK: call.sqrt: +; CHECK-NEXT: [[TMP1:%.*]] = tail call float @sqrtf(float [[VAL]]) [[WO:#[0-9]+]] +; CHECK-NEXT: br label [[ENTRY_SPLIT]] +; CHECK: entry.split: +; CHECK-NEXT: [[TMP2:%.*]] = phi float [ [[RES]], [[ENTRY:%.*]] ], [ [[TMP1]], [[CALL_SQRT]] ] +; CHECK-NEXT: ret float [[TMP2]] +; +entry: + %res = tail call float @sqrtf(float %val) #0 + ret float %res +} + declare float @sqrtf(float) + +; CHECK: attributes [[RN]] = { readnone } +; CHECK: attributes [[WO]] = { writeonly } +attributes #0 = { writeonly }