llvm-6502/lib/Analysis
Mehdi Amini 4c8f5afd99 InstCombine: fix fold "fcmp x, undef" to account for NaN
Summary:
See the two test cases.

; Can fold fcmp with undef on one side by choosing NaN for the undef

; Can fold fcmp with undef on both side
;   fcmp u_pred undef, undef -> true
;   fcmp o_pred undef, undef -> false
; because whatever you choose for the first undef
; you can choose NaN for the other undef

Reviewers: hfinkel, chandlerc, majnemer

Reviewed By: majnemer

Subscribers: majnemer, llvm-commits

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

From: Mehdi Amini <mehdi.amini@apple.com>

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@231626 91177308-0d34-0410-b5e6-96231b3b80d8
2015-03-09 03:20:25 +00:00
..
IPA Make DataLayout Non-Optional in the Module 2015-03-04 18:43:29 +00:00
AliasAnalysis.cpp Make DataLayout Non-Optional in the Module 2015-03-04 18:43:29 +00:00
AliasAnalysisCounter.cpp Make DataLayout Non-Optional in the Module 2015-03-04 18:43:29 +00:00
AliasAnalysisEvaluator.cpp
AliasDebugger.cpp Make DataLayout Non-Optional in the Module 2015-03-04 18:43:29 +00:00
AliasSetTracker.cpp
Analysis.cpp
AssumptionCache.cpp
BasicAliasAnalysis.cpp Make DataLayout Non-Optional in the Module 2015-03-04 18:43:29 +00:00
BlockFrequencyInfo.cpp
BlockFrequencyInfoImpl.cpp
BranchProbabilityInfo.cpp
CaptureTracking.cpp
CFG.cpp
CFGPrinter.cpp
CFLAliasAnalysis.cpp Make DataLayout Non-Optional in the Module 2015-03-04 18:43:29 +00:00
CGSCCPassManager.cpp
CMakeLists.txt
CodeMetrics.cpp
ConstantFolding.cpp
CostModel.cpp
Delinearization.cpp
DependenceAnalysis.cpp Reformat. 2015-03-05 01:25:19 +00:00
DominanceFrontier.cpp
DomPrinter.cpp
InstCount.cpp
InstructionSimplify.cpp InstCombine: fix fold "fcmp x, undef" to account for NaN 2015-03-09 03:20:25 +00:00
Interval.cpp
IntervalPartition.cpp
IVUsers.cpp Make DataLayout Non-Optional in the Module 2015-03-04 18:43:29 +00:00
LazyCallGraph.cpp
LazyValueInfo.cpp Make DataLayout Non-Optional in the Module 2015-03-04 18:43:29 +00:00
LibCallAliasAnalysis.cpp Make DataLayout Non-Optional in the Module 2015-03-04 18:43:29 +00:00
LibCallSemantics.cpp
Lint.cpp Make static variables const if possible. Makes them go into a read-only section. 2015-03-08 16:07:39 +00:00
LLVMBuild.txt
Loads.cpp Make DataLayout Non-Optional in the Module 2015-03-04 18:43:29 +00:00
LoopAccessAnalysis.cpp Make DataLayout Non-Optional in the Module 2015-03-04 18:43:29 +00:00
LoopInfo.cpp
LoopPass.cpp
Makefile
MemDepPrinter.cpp
MemDerefPrinter.cpp Make DataLayout Non-Optional in the Module 2015-03-04 18:43:29 +00:00
MemoryBuiltins.cpp DCE: isArrayMalloc() is not used neither in LLVM nor Clang 2015-03-09 02:57:32 +00:00
MemoryDependenceAnalysis.cpp Make DataLayout Non-Optional in the Module 2015-03-04 18:43:29 +00:00
ModuleDebugInfoPrinter.cpp
NoAliasAnalysis.cpp Make DataLayout Non-Optional in the Module 2015-03-04 18:43:29 +00:00
PHITransAddr.cpp
PostDominators.cpp
PtrUseVisitor.cpp
README.txt
RegionInfo.cpp
RegionPass.cpp Avoid calls to dumpPassInfo and RegionBase<Tr>::getNameStr() in RGPassManager if 2015-03-06 16:15:04 +00:00
RegionPrinter.cpp
ScalarEvolution.cpp Simplify expressions involving boolean constants with clang-tidy 2015-03-09 01:57:13 +00:00
ScalarEvolutionAliasAnalysis.cpp Make DataLayout Non-Optional in the Module 2015-03-04 18:43:29 +00:00
ScalarEvolutionExpander.cpp
ScalarEvolutionNormalization.cpp
ScopedNoAliasAA.cpp Make DataLayout Non-Optional in the Module 2015-03-04 18:43:29 +00:00
SparsePropagation.cpp
StratifiedSets.h
TargetLibraryInfo.cpp Make static variables const if possible. Makes them go into a read-only section. 2015-03-08 16:07:39 +00:00
TargetTransformInfo.cpp Do not restrict interleaved unrolling to small loops, depending on the target. 2015-03-06 23:12:04 +00:00
Trace.cpp
TypeBasedAliasAnalysis.cpp Make DataLayout Non-Optional in the Module 2015-03-04 18:43:29 +00:00
ValueTracking.cpp Teach ComputeNumSignBits about signed reminder. 2015-03-06 00:23:58 +00:00

Analysis Opportunities:

//===---------------------------------------------------------------------===//

In test/Transforms/LoopStrengthReduce/quadradic-exit-value.ll, the
ScalarEvolution expression for %r is this:

  {1,+,3,+,2}<loop>

Outside the loop, this could be evaluated simply as (%n * %n), however
ScalarEvolution currently evaluates it as

  (-2 + (2 * (trunc i65 (((zext i64 (-2 + %n) to i65) * (zext i64 (-1 + %n) to i65)) /u 2) to i64)) + (3 * %n))

In addition to being much more complicated, it involves i65 arithmetic,
which is very inefficient when expanded into code.

//===---------------------------------------------------------------------===//

In formatValue in test/CodeGen/X86/lsr-delayed-fold.ll,

ScalarEvolution is forming this expression:

((trunc i64 (-1 * %arg5) to i32) + (trunc i64 %arg5 to i32) + (-1 * (trunc i64 undef to i32)))

This could be folded to

(-1 * (trunc i64 undef to i32))

//===---------------------------------------------------------------------===//