[llvm] r361693 - [LVI][CVP] Calculate with.overflow result range
Nikita Popov via llvm-commits
llvm-commits at lists.llvm.org
Sat May 25 02:53:45 PDT 2019
Author: nikic
Date: Sat May 25 02:53:45 2019
New Revision: 361693
URL: http://llvm.org/viewvc/llvm-project?rev=361693&view=rev
Log:
[LVI][CVP] Calculate with.overflow result range
In LVI, calculate the range of extractvalue(op.with.overflow(%x, %y), 0)
as the range of op(%x, %y). This is mainly useful in conjunction with
D60650: If the result of the operation is extracted in a branch guarded
against overflow, then the value of %x will be appropriately constrained
and the result range of the operation will be calculated taking that
into account.
Differential Revision: https://reviews.llvm.org/D60656
Modified:
llvm/trunk/lib/Analysis/LazyValueInfo.cpp
llvm/trunk/test/Transforms/CorrelatedValuePropagation/overflow_predicate.ll
Modified: llvm/trunk/lib/Analysis/LazyValueInfo.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Analysis/LazyValueInfo.cpp?rev=361693&r1=361692&r2=361693&view=diff
==============================================================================
--- llvm/trunk/lib/Analysis/LazyValueInfo.cpp (original)
+++ llvm/trunk/lib/Analysis/LazyValueInfo.cpp Sat May 25 02:53:45 2019
@@ -430,6 +430,8 @@ namespace {
BasicBlock *BB);
bool solveBlockValueCast(ValueLatticeElement &BBLV, CastInst *CI,
BasicBlock *BB);
+ bool solveBlockValueOverflowIntrinsic(
+ ValueLatticeElement &BBLV, WithOverflowInst *WO, BasicBlock *BB);
void intersectAssumeOrGuardBlockValueConstantRange(Value *Val,
ValueLatticeElement &BBLV,
Instruction *BBI);
@@ -642,6 +644,11 @@ bool LazyValueInfoImpl::solveBlockValueI
if (BinaryOperator *BO = dyn_cast<BinaryOperator>(BBI))
return solveBlockValueBinaryOp(Res, BO, BB);
+
+ if (auto *EVI = dyn_cast<ExtractValueInst>(BBI))
+ if (auto *WO = dyn_cast<WithOverflowInst>(EVI->getAggregateOperand()))
+ if (EVI->getNumIndices() == 1 && *EVI->idx_begin() == 0)
+ return solveBlockValueOverflowIntrinsic(Res, WO, BB);
}
LLVM_DEBUG(dbgs() << " compute BB '" << BB->getName()
@@ -1097,6 +1104,14 @@ bool LazyValueInfoImpl::solveBlockValueB
};
}
+bool LazyValueInfoImpl::solveBlockValueOverflowIntrinsic(
+ ValueLatticeElement &BBLV, WithOverflowInst *WO, BasicBlock *BB) {
+ return solveBlockValueBinaryOpImpl(BBLV, WO, BB,
+ [WO](const ConstantRange &CR1, const ConstantRange &CR2) {
+ return CR1.binaryOp(WO->getBinaryOp(), CR2);
+ });
+}
+
static ValueLatticeElement getValueFromICmpCondition(Value *Val, ICmpInst *ICI,
bool isTrueDest) {
Value *LHS = ICI->getOperand(0);
Modified: llvm/trunk/test/Transforms/CorrelatedValuePropagation/overflow_predicate.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Transforms/CorrelatedValuePropagation/overflow_predicate.ll?rev=361693&r1=361692&r2=361693&view=diff
==============================================================================
--- llvm/trunk/test/Transforms/CorrelatedValuePropagation/overflow_predicate.ll (original)
+++ llvm/trunk/test/Transforms/CorrelatedValuePropagation/overflow_predicate.ll Sat May 25 02:53:45 2019
@@ -470,8 +470,7 @@ define i1 @uadd_val(i8 %x, i1* %pc) {
; CHECK: split:
; CHECK-NEXT: [[C1:%.*]] = icmp ugt i8 [[VAL]], 100
; CHECK-NEXT: store i1 [[C1]], i1* [[PC:%.*]]
-; CHECK-NEXT: [[C2:%.*]] = icmp uge i8 [[VAL]], 100
-; CHECK-NEXT: ret i1 [[C2]]
+; CHECK-NEXT: ret i1 true
; CHECK: trap:
; CHECK-NEXT: call void @llvm.trap()
; CHECK-NEXT: unreachable
@@ -506,8 +505,7 @@ define i1 @sadd_val(i8 %x, i1* %pc) {
; CHECK: split:
; CHECK-NEXT: [[C1:%.*]] = icmp sgt i8 [[VAL]], -28
; CHECK-NEXT: store i1 [[C1]], i1* [[PC:%.*]]
-; CHECK-NEXT: [[C2:%.*]] = icmp sge i8 [[VAL]], -28
-; CHECK-NEXT: ret i1 [[C2]]
+; CHECK-NEXT: ret i1 true
; CHECK: trap:
; CHECK-NEXT: call void @llvm.trap()
; CHECK-NEXT: unreachable
@@ -542,8 +540,7 @@ define i1 @usub_val(i8 %x, i1* %pc) {
; CHECK: split:
; CHECK-NEXT: [[C1:%.*]] = icmp ult i8 [[VAL]], -101
; CHECK-NEXT: store i1 [[C1]], i1* [[PC:%.*]]
-; CHECK-NEXT: [[C2:%.*]] = icmp ule i8 [[VAL]], -101
-; CHECK-NEXT: ret i1 [[C2]]
+; CHECK-NEXT: ret i1 true
; CHECK: trap:
; CHECK-NEXT: call void @llvm.trap()
; CHECK-NEXT: unreachable
@@ -578,8 +575,7 @@ define i1 @ssub_val(i8 %x, i1* %pc) {
; CHECK: split:
; CHECK-NEXT: [[C1:%.*]] = icmp slt i8 [[VAL]], 27
; CHECK-NEXT: store i1 [[C1]], i1* [[PC:%.*]]
-; CHECK-NEXT: [[C2:%.*]] = icmp sle i8 [[VAL]], 27
-; CHECK-NEXT: ret i1 [[C2]]
+; CHECK-NEXT: ret i1 true
; CHECK: trap:
; CHECK-NEXT: call void @llvm.trap()
; CHECK-NEXT: unreachable
@@ -614,8 +610,7 @@ define i1 @umul_val(i8 %x, i1* %pc) {
; CHECK: split:
; CHECK-NEXT: [[C1:%.*]] = icmp ult i8 [[VAL]], -6
; CHECK-NEXT: store i1 [[C1]], i1* [[PC:%.*]]
-; CHECK-NEXT: [[C2:%.*]] = icmp ule i8 [[VAL]], -6
-; CHECK-NEXT: ret i1 [[C2]]
+; CHECK-NEXT: ret i1 true
; CHECK: trap:
; CHECK-NEXT: call void @llvm.trap()
; CHECK-NEXT: unreachable
@@ -650,8 +645,7 @@ define i1 @smul_val_bound1(i8 %x, i1* %p
; CHECK: split:
; CHECK-NEXT: [[C1:%.*]] = icmp slt i8 [[VAL]], 120
; CHECK-NEXT: store i1 [[C1]], i1* [[PC:%.*]]
-; CHECK-NEXT: [[C2:%.*]] = icmp sle i8 [[VAL]], 120
-; CHECK-NEXT: ret i1 [[C2]]
+; CHECK-NEXT: ret i1 true
; CHECK: trap:
; CHECK-NEXT: call void @llvm.trap()
; CHECK-NEXT: unreachable
@@ -686,8 +680,7 @@ define i1 @smul_val_bound2(i8 %x, i1* %p
; CHECK: split:
; CHECK-NEXT: [[C1:%.*]] = icmp sgt i8 [[VAL]], -120
; CHECK-NEXT: store i1 [[C1]], i1* [[PC:%.*]]
-; CHECK-NEXT: [[C2:%.*]] = icmp sge i8 [[VAL]], -120
-; CHECK-NEXT: ret i1 [[C2]]
+; CHECK-NEXT: ret i1 true
; CHECK: trap:
; CHECK-NEXT: call void @llvm.trap()
; CHECK-NEXT: unreachable
More information about the llvm-commits
mailing list