ld_hoist1.ll 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. ; Test load hoist
  2. ; RUN: opt -basicaa -memdep -mldst-motion -S < %s | FileCheck %s
  3. target datalayout = "e-m:e-i64:64-f80:128-n8:16:32:64-S128"
  4. target triple = "x86_64-pc_linux"
  5. ; Function Attrs: nounwind uwtable
  6. define float* @foo(i32* noalias nocapture readonly %in, float* noalias %out, i32 %size, i32* nocapture readonly %trigger) {
  7. entry:
  8. %cmp11 = icmp eq i32 %size, 0
  9. br i1 %cmp11, label %for.end, label %for.body.lr.ph
  10. for.body.lr.ph: ; preds = %entry
  11. %0 = add i32 %size, -1
  12. br label %for.body
  13. ; CHECK-LABEL: for.body
  14. ; CHECK: load
  15. ; CHECK: %2 = getelementptr inbounds i32, i32* %in, i64 %indvars.iv
  16. ; CHECK: %3 = load i32, i32* %2, align 4
  17. for.body: ; preds = %for.body.lr.ph, %for.inc
  18. %indvars.iv = phi i64 [ 0, %for.body.lr.ph ], [ %indvars.iv.next, %for.inc ]
  19. %arrayidx = getelementptr inbounds i32, i32* %trigger, i64 %indvars.iv
  20. %1 = load i32, i32* %arrayidx, align 4
  21. %cmp1 = icmp sgt i32 %1, 0
  22. br i1 %cmp1, label %if.then, label %if.else
  23. ; CHECK-LABEL: if.then
  24. if.then: ; preds = %for.body
  25. ; This load should be hoisted
  26. %arrayidx3 = getelementptr inbounds i32, i32* %in, i64 %indvars.iv
  27. %2 = load i32, i32* %arrayidx3, align 4
  28. %conv = sitofp i32 %2 to float
  29. %add = fadd float %conv, 5.000000e-01
  30. %arrayidx5 = getelementptr inbounds float, float* %out, i64 %indvars.iv
  31. store float %add, float* %arrayidx5, align 4
  32. br label %for.inc
  33. if.else: ; preds = %for.body
  34. %arrayidx7 = getelementptr inbounds float, float* %out, i64 %indvars.iv
  35. %3 = load float, float* %arrayidx7, align 4
  36. %div = fdiv float %3, 3.000000e+00
  37. store float %div, float* %arrayidx7, align 4
  38. ; This load should be hoisted in spite of store
  39. %arrayidx9 = getelementptr inbounds i32, i32* %in, i64 %indvars.iv
  40. %4 = load i32, i32* %arrayidx9, align 4
  41. %conv10 = sitofp i32 %4 to float
  42. %add13 = fadd float %div, %conv10
  43. store float %add13, float* %arrayidx7, align 4
  44. br label %for.inc
  45. for.inc: ; preds = %if.then, %if.else
  46. %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
  47. %lftr.wideiv = trunc i64 %indvars.iv to i32
  48. %exitcond = icmp ne i32 %lftr.wideiv, %0
  49. br i1 %exitcond, label %for.body, label %for.cond.for.end_crit_edge
  50. for.cond.for.end_crit_edge: ; preds = %for.inc
  51. br label %for.end
  52. for.end: ; preds = %entry, %for.cond.for.end_crit_edge
  53. ret float* %out
  54. }