hoist-loads.ll 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. ; RUN: opt -loop-vectorize -force-vector-width=2 -force-vector-interleave=1 -S < %s | FileCheck %s
  2. 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"
  3. @A = common global [1024 x float] zeroinitializer, align 16
  4. @B = common global [1024 x float] zeroinitializer, align 16
  5. ; Make sure we can vectorize in the presence of hoistable conditional loads.
  6. ; CHECK-LABEL: @hoist_cond_load(
  7. ; CHECK: load <2 x float>
  8. define void @hoist_cond_load() {
  9. entry:
  10. br label %for.body
  11. for.body:
  12. %indvars.iv = phi i64 [ 0, %entry ], [ %indvars.iv.next, %if.end9 ]
  13. %arrayidx = getelementptr inbounds [1024 x float], [1024 x float]* @A, i64 0, i64 %indvars.iv
  14. %arrayidx2 = getelementptr inbounds [1024 x float], [1024 x float]* @B, i64 0, i64 %indvars.iv
  15. %0 = load float, float* %arrayidx2, align 4
  16. %cmp3 = fcmp oeq float %0, 0.000000e+00
  17. br i1 %cmp3, label %if.end9, label %if.else
  18. if.else:
  19. %1 = load float, float* %arrayidx, align 4
  20. br label %if.end9
  21. if.end9:
  22. %tmp.0 = phi float [ %1, %if.else ], [ 0.000000e+00, %for.body ]
  23. store float %tmp.0, float* %arrayidx, align 4
  24. %indvars.iv.next = add i64 %indvars.iv, 1
  25. %lftr.wideiv = trunc i64 %indvars.iv.next to i32
  26. %exitcond = icmp ne i32 %lftr.wideiv, 1024
  27. br i1 %exitcond, label %for.body, label %for.end
  28. for.end:
  29. ret void
  30. }
  31. ; However, we can't hoist loads whose address we have not seen unconditionally
  32. ; accessed.
  33. ; CHECK-LABEL: @dont_hoist_cond_load(
  34. ; CHECK-NOT: load <2 x float>
  35. define void @dont_hoist_cond_load() {
  36. entry:
  37. br label %for.body
  38. for.body:
  39. %indvars.iv = phi i64 [ 0, %entry ], [ %indvars.iv.next, %if.end9 ]
  40. %arrayidx = getelementptr inbounds [1024 x float], [1024 x float]* @A, i64 0, i64 %indvars.iv
  41. %arrayidx2 = getelementptr inbounds [1024 x float], [1024 x float]* @B, i64 0, i64 %indvars.iv
  42. %0 = load float, float* %arrayidx2, align 4
  43. %cmp3 = fcmp oeq float %0, 0.000000e+00
  44. br i1 %cmp3, label %if.end9, label %if.else
  45. if.else:
  46. %1 = load float, float* %arrayidx, align 4
  47. br label %if.end9
  48. if.end9:
  49. %tmp.0 = phi float [ %1, %if.else ], [ 0.000000e+00, %for.body ]
  50. store float %tmp.0, float* %arrayidx2, align 4
  51. %indvars.iv.next = add i64 %indvars.iv, 1
  52. %lftr.wideiv = trunc i64 %indvars.iv.next to i32
  53. %exitcond = icmp ne i32 %lftr.wideiv, 1024
  54. br i1 %exitcond, label %for.body, label %for.end
  55. for.end:
  56. ret void
  57. }