2
0

external_user.ll 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  1. ; RUN: opt < %s -basicaa -slp-vectorizer -dce -S -mtriple=x86_64-apple-macosx10.8.0 -mcpu=corei7-avx | 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. target triple = "x86_64-apple-macosx10.8.0"
  4. ; double foo(double * restrict b, double * restrict a, int n, int m) {
  5. ; double r=a[1];
  6. ; double g=a[0];
  7. ; double x;
  8. ; for (int i=0; i < 100; i++) {
  9. ; r += 10;
  10. ; g += 10;
  11. ; r *= 4;
  12. ; g *= 4;
  13. ; x = g; <----- external user!
  14. ; r += 4;
  15. ; g += 4;
  16. ; }
  17. ; b[0] = g;
  18. ; b[1] = r;
  19. ;
  20. ; return x; <-- must extract here!
  21. ; }
  22. ;CHECK: ext_user
  23. ;CHECK: phi <2 x double>
  24. ;CHECK: fadd <2 x double>
  25. ;CHECK: fmul <2 x double>
  26. ;CHECK: br
  27. ;CHECK: store <2 x double>
  28. ;CHECK: extractelement <2 x double>
  29. ;CHECK: ret double
  30. define double @ext_user(double* noalias nocapture %B, double* noalias nocapture %A, i32 %n, i32 %m) {
  31. entry:
  32. %arrayidx = getelementptr inbounds double, double* %A, i64 1
  33. %0 = load double, double* %arrayidx, align 8
  34. %1 = load double, double* %A, align 8
  35. br label %for.body
  36. for.body: ; preds = %for.body, %entry
  37. %i.020 = phi i32 [ 0, %entry ], [ %inc, %for.body ]
  38. %G.019 = phi double [ %1, %entry ], [ %add5, %for.body ]
  39. %R.018 = phi double [ %0, %entry ], [ %add4, %for.body ]
  40. %add = fadd double %R.018, 1.000000e+01
  41. %add2 = fadd double %G.019, 1.000000e+01
  42. %mul = fmul double %add, 4.000000e+00
  43. %mul3 = fmul double %add2, 4.000000e+00
  44. %add4 = fadd double %mul, 4.000000e+00
  45. %add5 = fadd double %mul3, 4.000000e+00
  46. %inc = add nsw i32 %i.020, 1
  47. %exitcond = icmp eq i32 %inc, 100
  48. br i1 %exitcond, label %for.end, label %for.body
  49. for.end: ; preds = %for.body
  50. store double %add5, double* %B, align 8
  51. %arrayidx7 = getelementptr inbounds double, double* %B, i64 1
  52. store double %add4, double* %arrayidx7, align 8
  53. ret double %mul3
  54. }
  55. ; A need-to-gather entry cannot be an external use of the scalar element.
  56. ; Instead the insertelement instructions of the need-to-gather entry are the
  57. ; external users.
  58. ; This test would assert because we would keep the scalar fpext and fadd alive.
  59. ; PR18129
  60. ; CHECK-LABEL: needtogather
  61. define i32 @needtogather(double *noalias %a, i32 *noalias %b, float * noalias %c,
  62. i32 * noalias %d) {
  63. entry:
  64. %0 = load i32, i32* %d, align 4
  65. %conv = sitofp i32 %0 to float
  66. %1 = load float, float* %c
  67. %sub = fsub float 0.000000e+00, %1
  68. %mul = fmul float %sub, 0.000000e+00
  69. %add = fadd float %conv, %mul
  70. %conv1 = fpext float %add to double
  71. %sub3 = fsub float 1.000000e+00, %1
  72. %mul4 = fmul float %sub3, 0.000000e+00
  73. %add5 = fadd float %conv, %mul4
  74. %conv6 = fpext float %add5 to double
  75. %tobool = fcmp une float %add, 0.000000e+00
  76. br i1 %tobool, label %if.then, label %if.end
  77. if.then:
  78. br label %if.end
  79. if.end:
  80. %storemerge = phi double [ %conv6, %if.then ], [ %conv1, %entry ]
  81. %e.0 = phi double [ %conv1, %if.then ], [ %conv6, %entry ]
  82. store double %storemerge, double* %a, align 8
  83. %conv7 = fptosi double %e.0 to i32
  84. store i32 %conv7, i32* %b, align 4
  85. ret i32 undef
  86. }