[llvm] r362254 - Revert "[CVP] Simplify non-overflowing saturating add/sub"
Nikita Popov via llvm-commits
llvm-commits at lists.llvm.org
Fri May 31 12:04:49 PDT 2019
Author: nikic
Date: Fri May 31 12:04:47 2019
New Revision: 362254
URL: http://llvm.org/viewvc/llvm-project?rev=362254&view=rev
Log:
Revert "[CVP] Simplify non-overflowing saturating add/sub"
This reverts commit 1e692d1777ae34dcb93524b5798651a29defae09.
Causes assertion failure in builtins-wasm.c clang test.
Modified:
llvm/trunk/lib/Transforms/Scalar/CorrelatedValuePropagation.cpp
llvm/trunk/test/Transforms/CorrelatedValuePropagation/overflows.ll
Modified: llvm/trunk/lib/Transforms/Scalar/CorrelatedValuePropagation.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Transforms/Scalar/CorrelatedValuePropagation.cpp?rev=362254&r1=362253&r2=362254&view=diff
==============================================================================
--- llvm/trunk/lib/Transforms/Scalar/CorrelatedValuePropagation.cpp (original)
+++ llvm/trunk/lib/Transforms/Scalar/CorrelatedValuePropagation.cpp Fri May 31 12:04:47 2019
@@ -63,8 +63,6 @@ STATISTIC(NumUDivs, "Number of udivs
STATISTIC(NumAShrs, "Number of ashr converted to lshr");
STATISTIC(NumSRems, "Number of srem converted to urem");
STATISTIC(NumOverflows, "Number of overflow checks removed");
-STATISTIC(NumSaturating,
- "Number of saturating arithmetics converted to normal arithmetics");
static cl::opt<bool> DontAddNoWrapFlags("cvp-dont-add-nowrap-flags", cl::init(true));
@@ -415,7 +413,7 @@ static void processOverflowIntrinsic(Wit
IRBuilder<> B(WO);
Value *NewOp = B.CreateBinOp(
WO->getBinaryOp(), WO->getLHS(), WO->getRHS(), WO->getName());
- // Constant-folding could have happened.
+ // Constant-holing could have happened.
if (auto *Inst = dyn_cast<Instruction>(NewOp)) {
if (WO->isSigned())
Inst->setHasNoSignedWrap();
@@ -430,20 +428,6 @@ static void processOverflowIntrinsic(Wit
++NumOverflows;
}
-static void processSaturatingInst(SaturatingInst *SI) {
- BinaryOperator *BinOp = BinaryOperator::Create(
- SI->getBinaryOp(), SI->getLHS(), SI->getRHS(), SI->getName(), SI);
- BinOp->setDebugLoc(SI->getDebugLoc());
- if (SI->isSigned())
- BinOp->setHasNoSignedWrap();
- else
- BinOp->setHasNoUnsignedWrap();
-
- SI->replaceAllUsesWith(BinOp);
- SI->eraseFromParent();
- ++NumSaturating;
-}
-
/// Infer nonnull attributes for the arguments at the specified callsite.
static bool processCallSite(CallSite CS, LazyValueInfo *LVI) {
SmallVector<unsigned, 4> ArgNos;
@@ -455,13 +439,6 @@ static bool processCallSite(CallSite CS,
return true;
}
}
-
- if (auto *SI = dyn_cast<SaturatingInst>(CS.getInstruction())) {
- if (willNotOverflow(SI, LVI)) {
- processSaturatingInst(SI);
- return true;
- }
- }
// Deopt bundle operands are intended to capture state with minimal
// perturbance of the code otherwise. If we can find a constant value for
Modified: llvm/trunk/test/Transforms/CorrelatedValuePropagation/overflows.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Transforms/CorrelatedValuePropagation/overflows.ll?rev=362254&r1=362253&r2=362254&view=diff
==============================================================================
--- llvm/trunk/test/Transforms/CorrelatedValuePropagation/overflows.ll (original)
+++ llvm/trunk/test/Transforms/CorrelatedValuePropagation/overflows.ll Fri May 31 12:04:47 2019
@@ -739,8 +739,8 @@ define i8 @uadd_sat_no_overflow(i8 %x) {
; CHECK-NEXT: call void @llvm.trap()
; CHECK-NEXT: unreachable
; CHECK: cont:
-; CHECK-NEXT: [[RES1:%.*]] = add nuw i8 [[X]], 100
-; CHECK-NEXT: ret i8 [[RES1]]
+; CHECK-NEXT: [[RES:%.*]] = call i8 @llvm.uadd.sat.i8(i8 [[X]], i8 100)
+; CHECK-NEXT: ret i8 [[RES]]
;
%cmp = icmp ugt i8 %x, 100
br i1 %cmp, label %trap, label %cont
@@ -762,8 +762,8 @@ define i8 @sadd_sat_no_overflow(i8 %x) {
; CHECK-NEXT: call void @llvm.trap()
; CHECK-NEXT: unreachable
; CHECK: cont:
-; CHECK-NEXT: [[RES1:%.*]] = add nsw i8 [[X]], 20
-; CHECK-NEXT: ret i8 [[RES1]]
+; CHECK-NEXT: [[RES:%.*]] = call i8 @llvm.sadd.sat.i8(i8 [[X]], i8 20)
+; CHECK-NEXT: ret i8 [[RES]]
;
%cmp = icmp sgt i8 %x, 100
br i1 %cmp, label %trap, label %cont
@@ -785,8 +785,8 @@ define i8 @usub_sat_no_overflow(i8 %x) {
; CHECK-NEXT: call void @llvm.trap()
; CHECK-NEXT: unreachable
; CHECK: cont:
-; CHECK-NEXT: [[RES1:%.*]] = sub nuw i8 [[X]], 100
-; CHECK-NEXT: ret i8 [[RES1]]
+; CHECK-NEXT: [[RES:%.*]] = call i8 @llvm.usub.sat.i8(i8 [[X]], i8 100)
+; CHECK-NEXT: ret i8 [[RES]]
;
%cmp = icmp ult i8 %x, 100
br i1 %cmp, label %trap, label %cont
@@ -808,8 +808,8 @@ define i8 @ssub_sat_no_overflow(i8 %x) {
; CHECK-NEXT: call void @llvm.trap()
; CHECK-NEXT: unreachable
; CHECK: cont:
-; CHECK-NEXT: [[RES1:%.*]] = sub nsw i8 [[X]], 20
-; CHECK-NEXT: ret i8 [[RES1]]
+; CHECK-NEXT: [[RES:%.*]] = call i8 @llvm.ssub.sat.i8(i8 [[X]], i8 20)
+; CHECK-NEXT: ret i8 [[RES]]
;
%cmp = icmp slt i8 %x, -100
br i1 %cmp, label %trap, label %cont
More information about the llvm-commits
mailing list