2
0

malloc-load-removal.ll 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. ; RUN: opt -S -basicaa -gvn < %s | FileCheck %s
  2. ; RUN: opt -S -basicaa -gvn -disable-simplify-libcalls < %s | FileCheck %s -check-prefix=CHECK_NO_LIBCALLS
  3. ; PR13694
  4. target datalayout = "e-p:64:64:64-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:64:64-f32:32:32-f64:64:64-v64:64:64-v128:128:128-a0:0:64-s0:64:64-f80:128:128-n8:16:32:64-S128"
  5. target triple = "x86_64-apple-macosx10.8.0"
  6. declare i8* @malloc(i64) nounwind
  7. define noalias i8* @test1() nounwind uwtable ssp {
  8. entry:
  9. %call = tail call i8* @malloc(i64 100) nounwind
  10. %0 = load i8, i8* %call, align 1
  11. %tobool = icmp eq i8 %0, 0
  12. br i1 %tobool, label %if.end, label %if.then
  13. if.then: ; preds = %entry
  14. store i8 0, i8* %call, align 1
  15. br label %if.end
  16. if.end: ; preds = %if.then, %entry
  17. ret i8* %call
  18. ; CHECK-LABEL: @test1(
  19. ; CHECK-NOT: load
  20. ; CHECK-NOT: icmp
  21. ; CHECK_NO_LIBCALLS-LABEL: @test1(
  22. ; CHECK_NO_LIBCALLS: load
  23. ; CHECK_NO_LIBCALLS: icmp
  24. }
  25. declare i8* @_Znwm(i64) nounwind
  26. define noalias i8* @test2() nounwind uwtable ssp {
  27. entry:
  28. %call = tail call i8* @_Znwm(i64 100) nounwind
  29. %0 = load i8, i8* %call, align 1
  30. %tobool = icmp eq i8 %0, 0
  31. br i1 %tobool, label %if.end, label %if.then
  32. if.then: ; preds = %entry
  33. store i8 0, i8* %call, align 1
  34. br label %if.end
  35. if.end: ; preds = %if.then, %entry
  36. ret i8* %call
  37. ; CHECK-LABEL: @test2(
  38. ; CHECK-NOT: load
  39. ; CHECK-NOT: icmp
  40. ; CHECK_NO_LIBCALLS-LABEL: @test2(
  41. ; CHECK_NO_LIBCALLS: load
  42. ; CHECK_NO_LIBCALLS: icmp
  43. }