[PATCH] D68654: [CVP} Replace SExt with ZExt if the input is known-non-negative
Roman Lebedev via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Tue Oct 8 13:36:17 PDT 2019
This revision was automatically updated to reflect the committed changes.
Closed by commit rG354ba6985ca0: [CVP} Replace SExt with ZExt if the input is known-non-negative (authored by lebedev.ri).
Changed prior to commit:
https://reviews.llvm.org/D68654?vs=223904&id=223933#toc
Repository:
rG LLVM Github Monorepo
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D68654/new/
https://reviews.llvm.org/D68654
Files:
llvm/lib/Transforms/Scalar/CorrelatedValuePropagation.cpp
llvm/test/Transforms/CorrelatedValuePropagation/sext.ll
Index: llvm/test/Transforms/CorrelatedValuePropagation/sext.ll
===================================================================
--- llvm/test/Transforms/CorrelatedValuePropagation/sext.ll
+++ llvm/test/Transforms/CorrelatedValuePropagation/sext.ll
@@ -18,9 +18,9 @@
; CHECK-NEXT: [[CMP:%.*]] = icmp sgt i32 [[A]], -1
; CHECK-NEXT: br i1 [[CMP]], label [[FOR_BODY]], label [[FOR_END:%.*]]
; CHECK: for.body:
-; CHECK-NEXT: [[EXT_WIDE:%.*]] = sext i32 [[A]] to i64
-; CHECK-NEXT: call void @use64(i64 [[EXT_WIDE]])
-; CHECK-NEXT: [[EXT]] = trunc i64 [[EXT_WIDE]] to i32
+; CHECK-NEXT: [[EXT_WIDE1:%.*]] = zext i32 [[A]] to i64
+; CHECK-NEXT: call void @use64(i64 [[EXT_WIDE1]])
+; CHECK-NEXT: [[EXT]] = trunc i64 [[EXT_WIDE1]] to i32
; CHECK-NEXT: br label [[FOR_COND]]
; CHECK: for.end:
; CHECK-NEXT: ret void
@@ -85,9 +85,9 @@
; CHECK-NEXT: [[CMP:%.*]] = icmp sgt i32 [[N:%.*]], -1
; CHECK-NEXT: br i1 [[CMP]], label [[BB:%.*]], label [[EXIT:%.*]]
; CHECK: bb:
-; CHECK-NEXT: [[EXT_WIDE:%.*]] = sext i32 [[N]] to i64
-; CHECK-NEXT: call void @use64(i64 [[EXT_WIDE]])
-; CHECK-NEXT: [[EXT:%.*]] = trunc i64 [[EXT_WIDE]] to i32
+; CHECK-NEXT: [[EXT_WIDE1:%.*]] = zext i32 [[N]] to i64
+; CHECK-NEXT: call void @use64(i64 [[EXT_WIDE1]])
+; CHECK-NEXT: [[EXT:%.*]] = trunc i64 [[EXT_WIDE1]] to i32
; CHECK-NEXT: br label [[EXIT]]
; CHECK: exit:
; CHECK-NEXT: ret void
Index: llvm/lib/Transforms/Scalar/CorrelatedValuePropagation.cpp
===================================================================
--- llvm/lib/Transforms/Scalar/CorrelatedValuePropagation.cpp
+++ llvm/lib/Transforms/Scalar/CorrelatedValuePropagation.cpp
@@ -62,6 +62,7 @@
STATISTIC(NumUDivs, "Number of udivs whose width was decreased");
STATISTIC(NumAShrs, "Number of ashr converted to lshr");
STATISTIC(NumSRems, "Number of srem converted to urem");
+STATISTIC(NumSExt, "Number of sext converted to zext");
STATISTIC(NumOverflows, "Number of overflow checks removed");
STATISTIC(NumSaturating,
"Number of saturating arithmetics converted to normal arithmetics");
@@ -637,6 +638,27 @@
return true;
}
+static bool processSExt(SExtInst *SDI, LazyValueInfo *LVI) {
+ if (SDI->getType()->isVectorTy())
+ return false;
+
+ Value *Base = SDI->getOperand(0);
+
+ Constant *Zero = ConstantInt::get(Base->getType(), 0);
+ if (LVI->getPredicateAt(ICmpInst::ICMP_SGE, Base, Zero, SDI) !=
+ LazyValueInfo::True)
+ return false;
+
+ ++NumSExt;
+ auto *ZExt =
+ CastInst::CreateZExtOrBitCast(Base, SDI->getType(), SDI->getName(), SDI);
+ ZExt->setDebugLoc(SDI->getDebugLoc());
+ SDI->replaceAllUsesWith(ZExt);
+ SDI->eraseFromParent();
+
+ return true;
+}
+
static bool processBinOp(BinaryOperator *BinOp, LazyValueInfo *LVI) {
using OBO = OverflowingBinaryOperator;
@@ -745,6 +767,9 @@
case Instruction::AShr:
BBChanged |= processAShr(cast<BinaryOperator>(II), LVI);
break;
+ case Instruction::SExt:
+ BBChanged |= processSExt(cast<SExtInst>(II), LVI);
+ break;
case Instruction::Add:
case Instruction::Sub:
BBChanged |= processBinOp(cast<BinaryOperator>(II), LVI);
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D68654.223933.patch
Type: text/x-patch
Size: 3252 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20191008/4463011d/attachment.bin>
More information about the llvm-commits
mailing list