llvm.org GIT mirror
[SCEV] Teach computeSCEVAtScope benefit from one-input Phi. PR39673 SCEV does not propagate arguments through one-input Phis so as to make it easy for the SCEV expander (and related code) to preserve LCSSA. It's not entirely clear this restriction is neccessary, but for the moment it exists. For this reason, we don't analyze single-entry phi inputs. However it is possible that when an this input leaves the loop through LCSSA Phi, it is a provable constant. Missing that results in an order of optimization issue in loop exit value rewriting where we miss some oppurtunities based on order in which we visit sibling loops. This patch teaches computeSCEVAtScope about this case. We can generalize it later, but so far we can only replace LCSSA Phis with their constant loop-exiting values. We should probably also add similiar logic directly in the SCEV construction path itself. Patch by: mkazantsev (with revised commit message by me) Differential Revision: https://reviews.llvm.org/D58113 git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@363180 91177308-0d34-0410-b5e6-96231b3b80d8 Philip Reames 3 months ago
2 changed file(s) with 11 addition(s) and 2 deletion(s).
 8137 8137 if (RV) return getSCEV(RV); 8138 8138 } 8139 8139 } 8140 8141 // If there is a single-input Phi, evaluate it at our scope. If we can 8142 // prove that this replacement does not break LCSSA form, use new value. 8143 if (PN->getNumOperands() == 1) { 8144 const SCEV *Input = getSCEV(PN->getOperand(0)); 8145 const SCEV *InputAtScope = getSCEVAtScope(Input, L); 8146 // TODO: We can generalize it using LI.replacementPreservesLCSSAForm, 8147 // for the simplest case just support constants. 8148 if (isa(InputAtScope)) return InputAtScope; 8149 } 8140 8150 } 8141 8151 8142 8152 // Okay, this is an expression that we cannot symbolically evaluate
 20 20 ; CHECK-NEXT: [[CMP2:%.*]] = icmp ult i16 [[L2_ADD]], 2 21 21 ; CHECK-NEXT: br i1 [[CMP2]], label [[LOOP2]], label [[LOOP2_END:%.*]] 22 22 ; CHECK: loop2.end: 23 ; CHECK-NEXT: [[K2_ADD_LCSSA:%.*]] = phi i16 [ [[K2_ADD]], [[LOOP2]] ] 24 ; CHECK-NEXT: ret i16 [[K2_ADD_LCSSA]]⏎ 23 ; CHECK-NEXT: ret i16 184⏎ 25 24 ; 26 25 entry: 27 26 br label %loop1