llvm-project/llvm/test/Transforms/LoopStrengthReduce
Wei Mi a49559befb [SCEV] Try to reuse existing value during SCEV expansion
Current SCEV expansion will expand SCEV as a sequence of operations
and doesn't utilize the value already existed. This will introduce
redundent computation which may not be cleaned up throughly by
following optimizations.

This patch introduces an ExprValueMap which is a map from SCEV to the
set of equal values with the same SCEV. When a SCEV is expanded, the
set of values is checked and reused whenever possible before generating
a sequence of operations.

The original commit triggered regressions in Polly tests. The regressions
exposed two problems which have been fixed in current version.

1. Polly will generate a new function based on the old one. To generate an
instruction for the new function, it builds SCEV for the old instruction,
applies some tranformation on the SCEV generated, then expands the transformed
SCEV and insert the expanded value into new function. Because SCEV expansion
may reuse value cached in ExprValueMap, the value in old function may be
inserted into new function, which is wrong.
   In SCEVExpander::expand, there is a logic to check the cached value to
be used should dominate the insertion point. However, for the above
case, the check always passes. That is because the insertion point is
in a new function, which is unreachable from the old function. However
for unreachable node, DominatorTreeBase::dominates thinks it will be
dominated by any other node.
   The fix is to simply add a check that the cached value to be used in
expansion should be in the same function as the insertion point instruction.

2. When the SCEV is of scConstant type, expanding it directly is cheaper than
reusing a normal value cached. Although in the cached value set in ExprValueMap,
there is a Constant type value, but it is not easy to find it out -- the cached
Value set is not sorted according to the potential cost. Existing reuse logic
in SCEVExpander::expand simply chooses the first legal element from the cached
value set.
   The fix is that when the SCEV is of scConstant type, don't try the reuse
logic. simply expand it.

Differential Revision: http://reviews.llvm.org/D12090

llvm-svn: 259736
2016-02-04 01:27:38 +00:00
..
AArch64 [opaque pointer type] Add textual IR support for explicit type parameter to load instruction 2015-02-27 21:17:42 +00:00
AMDGPU LoopStrengthReduce: Try to pass address space to isLegalAddressingMode 2015-08-15 00:53:06 +00:00
ARM [ARM][NEON] Use address space in vld([1234]|[234]lane) and vst([1234]|[234]lane) instructions 2015-09-30 10:56:37 +00:00
NVPTX [NVPTX] truncating 64-bit to 32-bit is free 2015-08-20 20:59:02 +00:00
X86 Followup to 258750; update more tests to use .p2align . 2016-01-26 00:35:07 +00:00
2005-08-15-AddRecIV.ll [opaque pointer type] Add textual IR support for explicit type parameter to load instruction 2015-02-27 21:17:42 +00:00
2005-08-17-OutOfLoopVariant.ll [opaque pointer type] Add textual IR support for explicit type parameter to load instruction 2015-02-27 21:17:42 +00:00
2005-09-12-UsesOutOutsideOfLoop.ll
2007-04-23-UseIterator.ll [opaque pointer type] Add textual IR support for explicit type parameter to getelementptr instruction 2015-02-27 19:29:02 +00:00
2008-08-13-CmpStride.ll [opaque pointer type] Add textual IR support for explicit type parameter to the call instruction 2015-04-16 23:24:18 +00:00
2008-09-09-Overflow.ll [opaque pointer type] Add textual IR support for explicit type parameter to the call instruction 2015-04-16 23:24:18 +00:00
2009-01-13-nonconstant-stride-outside-loop.ll [opaque pointer type] Add textual IR support for explicit type parameter to the call instruction 2015-04-16 23:24:18 +00:00
2009-04-28-no-reduce-mul.ll [opaque pointer type] Add textual IR support for explicit type parameter to gep operator 2015-03-13 18:20:45 +00:00
2011-07-19-CritEdgeBreakCrash.ll [opaque pointer type] Add textual IR support for explicit type parameter to load instruction 2015-02-27 21:17:42 +00:00
2011-10-03-CritEdgeMerge.ll Make DataLayout Non-Optional in the Module 2015-03-04 18:43:29 +00:00
2011-10-06-ReusePhi.ll [LSR] canonicalize Prod*(1<<C) to Prod<<C 2015-06-24 19:28:40 +00:00
2011-10-13-SCEVChain.ll [opaque pointer type] Add textual IR support for explicit type parameter to getelementptr instruction 2015-02-27 19:29:02 +00:00
2011-10-14-IntPtr.ll [opaque pointer type] Add textual IR support for explicit type parameter to getelementptr instruction 2015-02-27 19:29:02 +00:00
2011-12-19-PostincQuadratic.ll [opaque pointer type] Add textual IR support for explicit type parameter to load instruction 2015-02-27 21:17:42 +00:00
2012-01-02-nopreheader.ll [opaque pointer type] Add textual IR support for explicit type parameter to getelementptr instruction 2015-02-27 19:29:02 +00:00
2012-01-16-nopreheader.ll [opaque pointer type] Add textual IR support for explicit type parameter to getelementptr instruction 2015-02-27 19:29:02 +00:00
2012-03-15-nopreheader.ll [opaque pointer type] Add textual IR support for explicit type parameter to load instruction 2015-02-27 21:17:42 +00:00
2012-03-26-constexpr.ll [opaque pointer type] Add textual IR support for explicit type parameter to load instruction 2015-02-27 21:17:42 +00:00
2012-07-13-ExpandUDiv.ll [opaque pointer type] Add textual IR support for explicit type parameter to load instruction 2015-02-27 21:17:42 +00:00
2012-07-18-LimitReassociate.ll [opaque pointer type] Add textual IR support for explicit type parameter to the call instruction 2015-04-16 23:24:18 +00:00
2013-01-05-IndBr.ll
2013-01-14-ReuseCast.ll [opaque pointer type] Add textual IR support for explicit type parameter to load instruction 2015-02-27 21:17:42 +00:00
addrec-gep-address-space.ll [opaque pointer type] Add textual IR support for explicit type parameter to load instruction 2015-02-27 21:17:42 +00:00
addrec-gep.ll [opaque pointer type] Add textual IR support for explicit type parameter to load instruction 2015-02-27 21:17:42 +00:00
address-space-loop.ll [opaque pointer type] Add textual IR support for explicit type parameter to load instruction 2015-02-27 21:17:42 +00:00
count-to-zero.ll Make DataLayout Non-Optional in the Module 2015-03-04 18:43:29 +00:00
dead-phi.ll
different-type-ivs.ll [opaque pointer type] Add textual IR support for explicit type parameter to the call instruction 2015-04-16 23:24:18 +00:00
dominate-assert.ll Move the personality function from LandingPadInst to Function 2015-06-17 20:52:32 +00:00
dont-hoist-simple-loop-constants.ll [opaque pointer type] Add textual IR support for explicit type parameter to getelementptr instruction 2015-02-27 19:29:02 +00:00
dont_insert_redundant_ops.ll [opaque pointer type] Add textual IR support for explicit type parameter to getelementptr instruction 2015-02-27 19:29:02 +00:00
dont_reduce_bytes.ll [opaque pointer type] Add textual IR support for explicit type parameter to getelementptr instruction 2015-02-27 19:29:02 +00:00
dont_reverse.ll Make DataLayout Non-Optional in the Module 2015-03-04 18:43:29 +00:00
ephemeral.ll [LSR] don't attempt to promote ephemeral values to indvars 2015-07-13 03:28:53 +00:00
exit_compare_live_range.ll
funclet.ll [LoopStrengthReduce] Don't rewrite PHIs with incoming values from CatchSwitches 2016-02-03 21:30:34 +00:00
hoist-parent-preheader.ll [opaque pointer type] Add textual IR support for explicit type parameter to getelementptr instruction 2015-02-27 19:29:02 +00:00
invariant_value_first.ll [opaque pointer type] Add textual IR support for explicit type parameter to getelementptr instruction 2015-02-27 19:29:02 +00:00
invariant_value_first_arg.ll [opaque pointer type] Add textual IR support for explicit type parameter to getelementptr instruction 2015-02-27 19:29:02 +00:00
ivchain.ll Make DataLayout Non-Optional in the Module 2015-03-04 18:43:29 +00:00
lsr-expand-quadratic.ll
negative-scale.ll [NoTTI] reject negative scale in addressing mode 2015-05-08 18:07:24 +00:00
nested-reduce.ll Make DataLayout Non-Optional in the Module 2015-03-04 18:43:29 +00:00
nonlinear-postinc.ll
ops_after_indvar.ll [opaque pointer type] Add textual IR support for explicit type parameter to getelementptr instruction 2015-02-27 19:29:02 +00:00
phi_node_update_multiple_preds.ll [opaque pointer type] Add textual IR support for explicit type parameter to getelementptr instruction 2015-02-27 19:29:02 +00:00
post-inc-icmpzero.ll [SCEV] Try to reuse existing value during SCEV expansion 2016-02-04 01:27:38 +00:00
pr2537.ll
pr2570.ll [opaque pointer type] Add textual IR support for explicit type parameter to load instruction 2015-02-27 21:17:42 +00:00
pr3086.ll [opaque pointer type] Add textual IR support for explicit type parameter to load instruction 2015-02-27 21:17:42 +00:00
pr3399.ll [opaque pointer type] Add textual IR support for explicit type parameter to load instruction 2015-02-27 21:17:42 +00:00
pr3571.ll [opaque pointer type] Add textual IR support for explicit type parameter to load instruction 2015-02-27 21:17:42 +00:00
pr12018.ll DI: Require subprogram definitions to be distinct 2015-08-28 20:26:49 +00:00
pr12048.ll [opaque pointer type] Add textual IR support for explicit type parameter to getelementptr instruction 2015-02-27 19:29:02 +00:00
pr12691.ll Make DataLayout Non-Optional in the Module 2015-03-04 18:43:29 +00:00
pr18165.ll [opaque pointer type] Add textual IR support for explicit type parameter to the call instruction 2015-04-16 23:24:18 +00:00
pr25541.ll [IR] Reformulate LLVM's EH funclet IR 2015-12-12 05:38:55 +00:00
preserve-gep-loop-variant.ll [opaque pointer type] Add textual IR support for explicit type parameter to getelementptr instruction 2015-02-27 19:29:02 +00:00
quadradic-exit-value.ll [SCEV] Mark AddExprs as nsw or nuw if legal 2015-10-22 19:57:19 +00:00
related_indvars.ll [opaque pointer type] Add textual IR support for explicit type parameter to getelementptr instruction 2015-02-27 19:29:02 +00:00
remove_indvar.ll Make DataLayout Non-Optional in the Module 2015-03-04 18:43:29 +00:00
scaling_factor_cost_crash.ll [opaque pointer type] Add textual IR support for explicit type parameter to getelementptr instruction 2015-02-27 19:29:02 +00:00
sext-ind-var.ll [SCEV] Apply NSW and NUW flags via poison value analysis for sub, mul and shl 2015-08-14 22:45:26 +00:00
share_code_in_preheader.ll [opaque pointer type] Add textual IR support for explicit type parameter to load instruction 2015-02-27 21:17:42 +00:00
share_ivs.ll
shl.ll [LSR] canonicalize Prod*(1<<C) to Prod<<C 2015-06-24 19:28:40 +00:00
uglygep-address-space.ll [opaque pointer type] Add textual IR support for explicit type parameter to load instruction 2015-02-27 21:17:42 +00:00
uglygep.ll [opaque pointer type] Add textual IR support for explicit type parameter to load instruction 2015-02-27 21:17:42 +00:00
use_postinc_value_outside_loop.ll [opaque pointer type] Add textual IR support for explicit type parameter to getelementptr instruction 2015-02-27 19:29:02 +00:00
var_stride_used_by_compare.ll [opaque pointer type] Add textual IR support for explicit type parameter to getelementptr instruction 2015-02-27 19:29:02 +00:00
variable_stride.ll Make DataLayout Non-Optional in the Module 2015-03-04 18:43:29 +00:00