llvm-6502/lib/Transforms/Scalar
Pete Cooper 71a4b301fd Loop idiom recognizer was replacing too many uses of popcount.
When spotting that a loop can use ctpop, we were incorrectly replacing all uses of a value with a value derived from ctpop.

The bug here was exposed because we were replacing a use prior to the ctpop with the ctpop value and so we have a use before def, i.e., we changed

 %tobool.5 = icmp ne i32 %num, 0
 store i1 %tobool.5, i1* %ptr
 br i1 %tobool.5, label %for.body.lr.ph, label %for.end

to

 store i1 %1, i1* %ptr
 %0 = call i32 @llvm.ctpop.i32(i32 %num)
 %1 = icmp ne i32 %0, 0
 br i1 %1, label %for.body.lr.ph, label %for.end

Even if we inserted the ctpop so that it dominates the store here, that would still be incorrect.  The store doesn’t want the result of ctpop.

The fix is very simple, and involves replacing only the branch condition with the ctpop instead of all uses.

Reviewed by Hal Finkel.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@242068 91177308-0d34-0410-b5e6-96231b3b80d8
2015-07-13 21:25:33 +00:00
..
ADCE.cpp Revert the new EH instructions 2015-07-10 07:15:17 +00:00
AlignmentFromAssumptions.cpp
BDCE.cpp Revert the new EH instructions 2015-07-10 07:15:17 +00:00
CMakeLists.txt
ConstantHoisting.cpp
ConstantProp.cpp
CorrelatedValuePropagation.cpp
DCE.cpp
DeadStoreElimination.cpp
EarlyCSE.cpp
FlattenCFGPass.cpp
Float2Int.cpp
GVN.cpp [PM/AA] Completely remove the AliasAnalysis::copyValue interface. 2015-07-11 04:39:00 +00:00
InductiveRangeCheckElimination.cpp
IndVarSimplify.cpp [IndVars] Try to use existing values in RewriteLoopExitValues. 2015-07-09 18:46:12 +00:00
JumpThreading.cpp Revert the new EH instructions 2015-07-10 07:15:17 +00:00
LICM.cpp [LICM] Don't try to sink values out of loops without any exits 2015-07-12 03:53:05 +00:00
LLVMBuild.txt
LoadCombine.cpp
LoopDeletion.cpp
LoopDistribute.cpp [LoopDist/LoopVer] Move LoopVersioning to a new module, NFC 2015-07-10 18:55:13 +00:00
LoopIdiomRecognize.cpp Loop idiom recognizer was replacing too many uses of popcount. 2015-07-13 21:25:33 +00:00
LoopInstSimplify.cpp
LoopInterchange.cpp Avoid using Loop::getSubLoopsVector. 2015-07-13 17:21:14 +00:00
LoopRerollPass.cpp
LoopRotation.cpp
LoopStrengthReduce.cpp
LoopUnrollPass.cpp Enable runtime unrolling with unroll pragma metadata 2015-07-13 18:26:27 +00:00
LoopUnswitch.cpp
LowerAtomic.cpp
LowerExpectIntrinsic.cpp
Makefile
MemCpyOptimizer.cpp
MergedLoadStoreMotion.cpp [PM/AA] Completely remove the AliasAnalysis::copyValue interface. 2015-07-11 04:39:00 +00:00
NaryReassociate.cpp
PartiallyInlineLibCalls.cpp
PlaceSafepoints.cpp
Reassociate.cpp
Reg2Mem.cpp
RewriteStatepointsForGC.cpp
SampleProfile.cpp
Scalar.cpp
Scalarizer.cpp
ScalarReplAggregates.cpp
SCCP.cpp Revert the new EH instructions 2015-07-10 07:15:17 +00:00
SeparateConstOffsetFromGEP.cpp
SimplifyCFGPass.cpp
Sink.cpp
SpeculativeExecution.cpp
SROA.cpp
StraightLineStrengthReduce.cpp
StructurizeCFG.cpp
TailRecursionElimination.cpp