[PATCH 4/4] Enable support for floating-point division reductions
authorYichao Yu <yyc1992@gmail.com>
Sat, 10 Jun 2017 12:45:13 +0000 (08:45 -0400)
committerGianfranco Costamagna <locutusofborg@debian.org>
Mon, 23 Mar 2020 10:59:23 +0000 (10:59 +0000)
Similar to fsub, fdiv can also be vectorized using fmul.

Gbp-Pq: Topic julia
Gbp-Pq: Name llvm-D34078-vectorize-fdiv.patch

lib/Transforms/Utils/LoopUtils.cpp
test/Transforms/LoopVectorize/float-reduction.ll

index 0a357f4b500441e5a8a977ab8680f609983a611b..1139c53ae2866e821cbe6816f7e1364545545cc2 100644 (file)
@@ -513,6 +513,7 @@ RecurrenceDescriptor::isRecurrenceInstr(Instruction *I, RecurrenceKind Kind,
     return InstDesc(Kind == RK_IntegerOr, I);
   case Instruction::Xor:
     return InstDesc(Kind == RK_IntegerXor, I);
+  case Instruction::FDiv:
   case Instruction::FMul:
     return InstDesc(Kind == RK_FloatMult, I, UAI);
   case Instruction::FSub:
index f3b95d0ead7d89c7a859832ec53c5a857da14987..669c54d55a290e4a46a605ef19e4a14221e9764a 100644 (file)
@@ -44,3 +44,25 @@ for.body:                                         ; preds = %for.body, %entry
 for.end:                                          ; preds = %for.body
   ret float %sub
 }
+
+;CHECK-LABEL: @foodiv(
+;CHECK: fdiv fast <4 x float>
+;CHECK: ret
+define float @foodiv(float* nocapture %A, i32* nocapture %n) nounwind uwtable readonly ssp {
+entry:
+  br label %for.body
+
+for.body:                                         ; preds = %for.body, %entry
+  %indvars.iv = phi i64 [ 0, %entry ], [ %indvars.iv.next, %for.body ]
+  %sum.04 = phi float [ 1.000000e+00, %entry ], [ %sub, %for.body ]
+  %arrayidx = getelementptr inbounds float, float* %A, i64 %indvars.iv
+  %0 = load float, float* %arrayidx, align 4
+  %sub = fdiv fast float %sum.04, %0
+  %indvars.iv.next = add i64 %indvars.iv, 1
+  %lftr.wideiv = trunc i64 %indvars.iv.next to i32
+  %exitcond = icmp eq i32 %lftr.wideiv, 200
+  br i1 %exitcond, label %for.end, label %for.body
+
+for.end:                                          ; preds = %for.body
+  ret float %sub
+}