[PATCH] D18867: [IndVarSimplify] Eliminate zext of a signed IV when the IV is known to be non-negative
Li Huang via llvm-commits
llvm-commits at lists.llvm.org
Thu Apr 7 13:58:55 PDT 2016
lihuang created this revision.
lihuang added reviewers: sanjoy, reames, mbodart.
lihuang added a subscriber: llvm-commits.
[IndVarSimplify] Eliminate zext of a signed IV when widening if the IV is known to be non-negative.
This was part of a previous diff (D18777), now separated into a new diff. This change eliminates zexts of IV when IV is treated as unsigned and is known to be non-negative.
The change in D18777 will fail a front-end test (Frontend/optimization-remark-options.c) and this change should fix this test.
http://reviews.llvm.org/D18867
Files:
lib/Transforms/Scalar/IndVarSimplify.cpp
Index: lib/Transforms/Scalar/IndVarSimplify.cpp
===================================================================
--- lib/Transforms/Scalar/IndVarSimplify.cpp
+++ lib/Transforms/Scalar/IndVarSimplify.cpp
@@ -35,6 +35,7 @@
#include "llvm/Analysis/ScalarEvolutionAliasAnalysis.h"
#include "llvm/Analysis/TargetLibraryInfo.h"
#include "llvm/Analysis/TargetTransformInfo.h"
+#include "llvm/Analysis/ValueTracking.h"
#include "llvm/IR/BasicBlock.h"
#include "llvm/IR/CFG.h"
#include "llvm/IR/Constants.h"
@@ -1304,7 +1305,8 @@
}
}
// Our raison d'etre! Eliminate sign and zero extension.
- if (IsSigned ? isa<SExtInst>(DU.NarrowUse) : isa<ZExtInst>(DU.NarrowUse)) {
+ if ((IsSigned ? isa<SExtInst>(DU.NarrowUse) : isa<ZExtInst>(DU.NarrowUse)) ||
+ (isa<ZExtInst>(DU.NarrowUse) && DU.NeverNegative)) {
Value *NewDef = DU.WideDef;
if (DU.NarrowUse->getType() != WideType) {
unsigned CastWidth = SE->getTypeSizeInBits(DU.NarrowUse->getType());
@@ -1396,7 +1398,8 @@
const SCEV *NarrowSCEV = SE->getSCEV(NarrowDef);
bool NeverNegative =
SE->isKnownPredicate(ICmpInst::ICMP_SGE, NarrowSCEV,
- SE->getConstant(NarrowSCEV->getType(), 0));
+ SE->getConstant(NarrowSCEV->getType(), 0)) ||
+ isKnownNonNegative(NarrowDef, NarrowDef->getModule()->getDataLayout(), 0);
for (User *U : NarrowDef->users()) {
Instruction *NarrowUser = cast<Instruction>(U);
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D18867.52951.patch
Type: text/x-patch
Size: 1460 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20160407/0e4bed13/attachment.bin>
More information about the llvm-commits
mailing list