if (!CI->use_empty())
return nullptr;
- // printf("x") -> putchar('x'), even for '%'.
- if (FormatStr.size() == 1)
+ // printf("x") -> putchar('x'), even for "%" and "%%".
+ if (FormatStr.size() == 1 || FormatStr == "%%")
return emitPutChar(B.getInt32(FormatStr[0]), B, TLI);
// printf("%s", "a") --> putchar('a')
@hello_world = constant [13 x i8] c"hello world\0A\00"
@h = constant [2 x i8] c"h\00"
+@h2 = constant [3 x i8] c"%%\00"
@percent = constant [2 x i8] c"%\00"
@percent_c = constant [3 x i8] c"%c\00"
@percent_d = constant [3 x i8] c"%d\00"
; CHECK-NEXT: ret void
}
+; Special case: printf("%%") -> putchar('%').
+
+define void @test_simplify2b() {
+; CHECK-LABEL: @test_simplify2b(
+ %fmt = getelementptr [3 x i8], [3 x i8]* @h2, i32 0, i32 0
+ call i32 (i8*, ...) @printf(i8* %fmt)
+; CHECK-NEXT: call i32 @putchar(i32 37)
+ ret void
+; CHECK-NEXT: ret void
+}
+
define void @test_simplify3() {
; CHECK-LABEL: @test_simplify3(
%fmt = getelementptr [2 x i8], [2 x i8]* @percent, i32 0, i32 0