puts-1.ll 949 B

12345678910111213141516171819202122232425262728293031
  1. ; Test that the puts library call simplifier works correctly.
  2. ;
  3. ; RUN: opt < %s -instcombine -S | FileCheck %s
  4. target datalayout = "e-p:32:32:32-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:32:64-f32:32:32-f64:32:64-v64:64:64-v128:128:128-a0:0:64-f80:128:128"
  5. @empty = constant [1 x i8] zeroinitializer
  6. declare i32 @puts(i8*)
  7. ; Check puts("") -> putchar('\n').
  8. define void @test_simplify1() {
  9. ; CHECK-LABEL: @test_simplify1(
  10. %str = getelementptr [1 x i8], [1 x i8]* @empty, i32 0, i32 0
  11. call i32 @puts(i8* %str)
  12. ; CHECK-NEXT: call i32 @putchar(i32 10)
  13. ret void
  14. ; CHECK-NEXT: ret void
  15. }
  16. ; Don't simplify if the return value is used.
  17. define i32 @test_no_simplify1() {
  18. ; CHECK-LABEL: @test_no_simplify1(
  19. %str = getelementptr [1 x i8], [1 x i8]* @empty, i32 0, i32 0
  20. %ret = call i32 @puts(i8* %str)
  21. ; CHECK-NEXT: call i32 @puts(i8* getelementptr inbounds ([1 x i8], [1 x i8]* @empty, i32 0, i32 0))
  22. ret i32 %ret
  23. ; CHECK-NEXT: ret i32 %ret
  24. }