mirror of
https://github.com/c64scene-ar/llvm-6502.git
synced 2025-06-16 12:24:03 +00:00
Do not optimise fprintf() calls if its return value is used.
Differential Revision: http://llvm-reviews.chandlerc.com/D620 git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@179661 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
@ -1518,6 +1518,12 @@ struct FPrintFOpt : public LibCallOptimization {
|
|||||||
if (!getConstantStringInfo(CI->getArgOperand(1), FormatStr))
|
if (!getConstantStringInfo(CI->getArgOperand(1), FormatStr))
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
|
// Do not do any of the following transformations if the fprintf return
|
||||||
|
// value is used, in general the fprintf return value is not compatible
|
||||||
|
// with fwrite(), fputc() or fputs().
|
||||||
|
if (!CI->use_empty())
|
||||||
|
return 0;
|
||||||
|
|
||||||
// fprintf(F, "foo") --> fwrite("foo", 3, 1, F)
|
// fprintf(F, "foo") --> fwrite("foo", 3, 1, F)
|
||||||
if (CI->getNumArgOperands() == 2) {
|
if (CI->getNumArgOperands() == 2) {
|
||||||
for (unsigned i = 0, e = FormatStr.size(); i != e; ++i)
|
for (unsigned i = 0, e = FormatStr.size(); i != e; ++i)
|
||||||
@ -1527,11 +1533,10 @@ struct FPrintFOpt : public LibCallOptimization {
|
|||||||
// These optimizations require DataLayout.
|
// These optimizations require DataLayout.
|
||||||
if (!TD) return 0;
|
if (!TD) return 0;
|
||||||
|
|
||||||
Value *NewCI = EmitFWrite(CI->getArgOperand(1),
|
return EmitFWrite(CI->getArgOperand(1),
|
||||||
ConstantInt::get(TD->getIntPtrType(*Context),
|
ConstantInt::get(TD->getIntPtrType(*Context),
|
||||||
FormatStr.size()),
|
FormatStr.size()),
|
||||||
CI->getArgOperand(0), B, TD, TLI);
|
CI->getArgOperand(0), B, TD, TLI);
|
||||||
return NewCI ? ConstantInt::get(CI->getType(), FormatStr.size()) : 0;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// The remaining optimizations require the format string to be "%s" or "%c"
|
// The remaining optimizations require the format string to be "%s" or "%c"
|
||||||
@ -1544,14 +1549,12 @@ struct FPrintFOpt : public LibCallOptimization {
|
|||||||
if (FormatStr[1] == 'c') {
|
if (FormatStr[1] == 'c') {
|
||||||
// fprintf(F, "%c", chr) --> fputc(chr, F)
|
// fprintf(F, "%c", chr) --> fputc(chr, F)
|
||||||
if (!CI->getArgOperand(2)->getType()->isIntegerTy()) return 0;
|
if (!CI->getArgOperand(2)->getType()->isIntegerTy()) return 0;
|
||||||
Value *NewCI = EmitFPutC(CI->getArgOperand(2), CI->getArgOperand(0), B,
|
return EmitFPutC(CI->getArgOperand(2), CI->getArgOperand(0), B, TD, TLI);
|
||||||
TD, TLI);
|
|
||||||
return NewCI ? ConstantInt::get(CI->getType(), 1) : 0;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (FormatStr[1] == 's') {
|
if (FormatStr[1] == 's') {
|
||||||
// fprintf(F, "%s", str) --> fputs(str, F)
|
// fprintf(F, "%s", str) --> fputs(str, F)
|
||||||
if (!CI->getArgOperand(2)->getType()->isPointerTy() || !CI->use_empty())
|
if (!CI->getArgOperand(2)->getType()->isPointerTy())
|
||||||
return 0;
|
return 0;
|
||||||
return EmitFPutS(CI->getArgOperand(2), CI->getArgOperand(0), B, TD, TLI);
|
return EmitFPutS(CI->getArgOperand(2), CI->getArgOperand(0), B, TD, TLI);
|
||||||
}
|
}
|
||||||
|
@ -78,3 +78,12 @@ define void @test_no_simplify2(%FILE* %fp, double %d) {
|
|||||||
ret void
|
ret void
|
||||||
; CHECK-NEXT: ret void
|
; CHECK-NEXT: ret void
|
||||||
}
|
}
|
||||||
|
|
||||||
|
define i32 @test_no_simplify3(%FILE* %fp) {
|
||||||
|
; CHECK: @test_no_simplify3
|
||||||
|
%fmt = getelementptr [13 x i8]* @hello_world, i32 0, i32 0
|
||||||
|
%1 = call i32 (%FILE*, i8*, ...)* @fprintf(%FILE* %fp, i8* %fmt)
|
||||||
|
; CHECK-NEXT: call i32 (%FILE*, i8*, ...)* @fprintf(%FILE* %fp, i8* getelementptr inbounds ([13 x i8]* @hello_world, i32 0, i32 0))
|
||||||
|
ret i32 %1
|
||||||
|
; CHECK-NEXT: ret i32 %1
|
||||||
|
}
|
||||||
|
Reference in New Issue
Block a user