1
0
mirror of https://github.com/RPCS3/llvm-mirror.git synced 2024-10-21 20:12:56 +02:00
llvm-mirror/test/Transforms
Sanjoy Das b20d278ebd Don't IPO over functions that can be de-refined
Summary:
Fixes PR26774.

If you're aware of the issue, feel free to skip the "Motivation"
section and jump directly to "This patch".

Motivation:

I define "refinement" as discarding behaviors from a program that the
optimizer has license to discard.  So transforming:

```
void f(unsigned x) {
  unsigned t = 5 / x;
  (void)t;
}
```

to

```
void f(unsigned x) { }
```

is refinement, since the behavior went from "if x == 0 then undefined
else nothing" to "nothing" (the optimizer has license to discard
undefined behavior).

Refinement is a fundamental aspect of many mid-level optimizations done
by LLVM.  For instance, transforming `x == (x + 1)` to `false` also
involves refinement since the expression's value went from "if x is
`undef` then { `true` or `false` } else { `false` }" to "`false`" (by
definition, the optimizer has license to fold `undef` to any non-`undef`
value).

Unfortunately, refinement implies that the optimizer cannot assume
that the implementation of a function it can see has all of the
behavior an unoptimized or a differently optimized version of the same
function can have.  This is a problem for functions with comdat
linkage, where a function can be replaced by an unoptimized or a
differently optimized version of the same source level function.

For instance, FunctionAttrs cannot assume a comdat function is
actually `readnone` even if it does not have any loads or stores in
it; since there may have been loads and stores in the "original
function" that were refined out in the currently visible variant, and
at the link step the linker may in fact choose an implementation with
a load or a store.  As an example, consider a function that does two
atomic loads from the same memory location, and writes to memory only
if the two values are not equal.  The optimizer is allowed to refine
this function by first CSE'ing the two loads, and the folding the
comparision to always report that the two values are equal.  Such a
refined variant will look like it is `readonly`.  However, the
unoptimized version of the function can still write to memory (since
the two loads //can// result in different values), and selecting the
unoptimized version at link time will retroactively invalidate
transforms we may have done under the assumption that the function
does not write to memory.

Note: this is not just a problem with atomics or with linking
differently optimized object files.  See PR26774 for more realistic
examples that involved neither.

This patch:

This change introduces a new set of linkage types, predicated as
`GlobalValue::mayBeDerefined` that returns true if the linkage type
allows a function to be replaced by a differently optimized variant at
link time.  It then changes a set of IPO passes to bail out if they see
such a function.

Reviewers: chandlerc, hfinkel, dexonsmith, joker.eph, rnk

Subscribers: mcrosier, llvm-commits

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

llvm-svn: 265762
2016-04-08 00:48:30 +00:00
..
ADCE testcase gardening: update the emissionKind enum to the new syntax. (NFC) 2016-04-01 00:16:49 +00:00
AddDiscriminators testcase gardening: update the emissionKind enum to the new syntax. (NFC) 2016-04-01 00:16:49 +00:00
AlignmentFromAssumptions
ArgumentPromotion testcase gardening: update the emissionKind enum to the new syntax. (NFC) 2016-04-01 00:16:49 +00:00
AtomicExpand ARM: sink atomic release barrier as far as possible into cmpxchg. 2016-02-22 20:55:50 +00:00
BBVectorize
BDCE
BranchFolding
CodeExtractor
CodeGenPrepare [CodeGenPrepare] Avoid sinking soft-FP comparisons 2016-04-03 16:36:17 +00:00
ConstantHoisting
ConstantMerge
ConstProp
CorrelatedValuePropagation [CVP] Convert an SDiv to a UDiv if both operands are known to be nonnegative 2016-03-14 03:24:28 +00:00
CrossDSOCFI
DeadArgElim testcase gardening: update the emissionKind enum to the new syntax. (NFC) 2016-04-01 00:16:49 +00:00
DeadStoreElimination testcase gardening: update the emissionKind enum to the new syntax. (NFC) 2016-04-01 00:16:49 +00:00
EarlyCSE
EliminateAvailableExternally
Float2Int
ForcedFunctionAttrs
FunctionAttrs Don't IPO over functions that can be de-refined 2016-04-08 00:48:30 +00:00
FunctionImport Fix bot errors from r265327, exact GUID which depends on path 2016-04-04 19:11:00 +00:00
GCOVProfiling testcase gardening: update the emissionKind enum to the new syntax. (NFC) 2016-04-01 00:16:49 +00:00
GlobalDCE
GlobalOpt testcase gardening: update the emissionKind enum to the new syntax. (NFC) 2016-04-01 00:16:49 +00:00
GVN [GVN] Fix handling of sub-byte types in big-endian mode 2016-04-07 15:45:02 +00:00
IndVarSimplify [IndVarSimplify] Don't insert after a catchswitch 2016-03-30 21:12:06 +00:00
InferFunctionAttrs [NVPTX] Infer __nvvm_reflect as nounwind, readnone 2016-03-31 21:29:57 +00:00
Inline Don't IPO over functions that can be de-refined 2016-04-08 00:48:30 +00:00
InstCombine regenerate checks 2016-04-06 19:58:06 +00:00
InstMerge fixed typo - CHECK-LABEL 2016-03-29 06:49:38 +00:00
InstSimplify [InstSimplify] regenerate checks using a script 2016-03-25 20:12:25 +00:00
Internalize
IPConstantProp Don't IPO over functions that can be de-refined 2016-04-08 00:48:30 +00:00
IRCE
JumpThreading [JumpThreading] See through Cast Instructions 2016-03-16 04:52:52 +00:00
LCSSA
LICM Mark some FP intrinsics as safe to speculatively execute 2016-04-03 12:30:46 +00:00
LoadCombine
LoopDataPrefetch [LoopDataPrefetch] Centralize the tuning cl::opts under the pass 2016-03-29 23:45:52 +00:00
LoopDeletion
LoopDistribute
LoopIdiom testcase gardening: update the emissionKind enum to the new syntax. (NFC) 2016-04-01 00:16:49 +00:00
LoopInterchange
LoopLoadElim [LLE] Check for mismatching types between the store and the load earlier 2016-03-24 17:59:26 +00:00
LoopReroll testcase gardening: update the emissionKind enum to the new syntax. (NFC) 2016-04-01 00:16:49 +00:00
LoopRotate testcase gardening: update the emissionKind enum to the new syntax. (NFC) 2016-04-01 00:16:49 +00:00
LoopSimplify [DebugInfo] Fix tests so that each subprogram belongs to a CU. 2016-04-05 23:37:08 +00:00
LoopSimplifyCFG
LoopStrengthReduce Don't delete empty preheaders in CodeGenPrepare if it would create a critical edge 2016-04-05 14:06:20 +00:00
LoopUnroll [LoopUnroll] Fix the way we update DT after complete unrolling. 2016-04-06 21:47:12 +00:00
LoopUnswitch [SimlifyCFG] Prevent passes from destroying canonical loop structure, especially for nested loops 2016-03-29 04:08:57 +00:00
LoopVectorize Revert r265535 until we know how we can fix the bots 2016-04-06 14:06:32 +00:00
LoopVersioning [LVers] Change CHECK_LABEL to CHECK-LABEL (underscore->dash) 2016-03-28 21:04:13 +00:00
LoopVersioningLICM
LowerAtomic
LowerBitSets
LowerExpectIntrinsic
LowerGuardIntrinsic Introduce a @llvm.experimental.guard intrinsic 2016-03-31 00:18:46 +00:00
LowerInvoke
LowerSwitch
Mem2Reg testcase gardening: update the emissionKind enum to the new syntax. (NFC) 2016-04-01 00:16:49 +00:00
MemCpyOpt Imporove load to store => memcpy 2016-03-14 22:52:27 +00:00
MergeFunc
MetaRenamer
NaryReassociate
ObjCARC Don't IPO over functions that can be de-refined 2016-04-08 00:48:30 +00:00
PartiallyInlineLibCalls
PGOProfile [PGO] Avoid instrumenting direct callee's at value sites. 2016-04-04 18:56:36 +00:00
PhaseOrdering
PlaceSafepoints
PruneEH
Reassociate
Reg2Mem
RewriteStatepointsForGC [RS4GC] Better codegen for deoptimize calls 2016-04-05 23:18:35 +00:00
SafeStack testcase gardening: update the emissionKind enum to the new syntax. (NFC) 2016-04-01 00:16:49 +00:00
SampleProfile testcase gardening: update the emissionKind enum to the new syntax. (NFC) 2016-04-01 00:16:49 +00:00
Scalarizer testcase gardening: update the emissionKind enum to the new syntax. (NFC) 2016-04-01 00:16:49 +00:00
ScalarRepl testcase gardening: update the emissionKind enum to the new syntax. (NFC) 2016-04-01 00:16:49 +00:00
SCCP Don't IPO over functions that can be de-refined 2016-04-08 00:48:30 +00:00
SeparateConstOffsetFromGEP [ValueTracking] Remove dead code from an old experiment 2016-03-03 19:44:06 +00:00
SimplifyCFG testcase gardening: update the emissionKind enum to the new syntax. (NFC) 2016-04-01 00:16:49 +00:00
Sink
SLPVectorizer [SLPVectorizer] Vectorizing the libm sqrt to llvm's sqrt intrinsic requires nnan 2016-04-06 07:04:53 +00:00
SpeculativeExecution
SROA Have DataLayout::isLegalInteger() accept uint64_t 2016-03-18 23:19:29 +00:00
StraightLineStrengthReduce
StripDeadPrototypes
StripSymbols testcase gardening: update the emissionKind enum to the new syntax. (NFC) 2016-04-01 00:16:49 +00:00
StructurizeCFG
TailCallElim
Util testcase gardening: update the emissionKind enum to the new syntax. (NFC) 2016-04-01 00:16:49 +00:00
WholeProgramDevirt