[PATCH] D31910: [LV] Avoid vectorizing first order recurrences when phi used outside loop
Matthew Simpson via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Tue Apr 11 13:27:19 PDT 2017
mssimpso added inline comments.
================
Comment at: lib/Transforms/Utils/LoopUtils.cpp:556-559
+ auto *Cmp = dyn_cast<CmpInst>(Latch->getTerminator()->getOperand(0));
+ bool LoopTermConditionUsesPhi = false;
+ if (Cmp && (Cmp->getOperand(0) == Phi || Cmp->getOperand(1) == Phi))
+ LoopTermConditionUsesPhi = true;
----------------
I don't think I understand this. Why do we need to check if the phi is used by the back-edge condition? If a phi is used by the back-edge condition, we should probably recognize it as an induction variable, not a first-order recurrence. I think you can remove this, and just check that the phi has no external users.
================
Comment at: test/Transforms/LoopVectorize/first-order-recurrence.ll:390-401
+for.body:
+ %inc.phi = phi i32 [ 0, %entry ], [ %inc, %for.body ]
+ %val.phi = phi i32 [ 0, %entry ], [ %addx, %for.body ]
+ %inc = add i32 %inc.phi, 1
+ %bc = zext i32 %inc.phi to i64
+ %addx = add i32 %inc.phi, %x
+ %cmp = icmp eq i32 %inc.phi, 95
----------------
In this test, "%inc.phi" is the induction variable and "%val.phi" is the potential first-order recurrence. We already allow induction variables to have external users, so we don't need to worry about this case. I think this test will pass without your patch.
https://reviews.llvm.org/D31910
More information about the llvm-commits
mailing list