From 171bf705980004dac14bab988ee8eaf20d9b3d9d Mon Sep 17 00:00:00 2001 From: Philip Reames Date: Tue, 26 Apr 2016 22:52:30 +0000 Subject: [PATCH] [LVI] A better fix for the assertion error introduced by 267609 Essentially, I was using the wrong size function. For types which were sized, but not primitive, I wasn't getting a useful size for the operand and failed an assert. I fixed this, and also added a guard that the input is a sized type. Test case is for the original mistake. I'm not sure how to actually exercise the sized type check. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@267618 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/Analysis/LazyValueInfo.cpp | 21 +++++++++++---------- test/Transforms/CorrelatedValuePropagation/basic.ll | 11 +++++++++++ 2 files changed, 22 insertions(+), 10 deletions(-) diff --git a/lib/Analysis/LazyValueInfo.cpp b/lib/Analysis/LazyValueInfo.cpp index 5f1d1790c79..6bc639cf8b2 100644 --- a/lib/Analysis/LazyValueInfo.cpp +++ b/lib/Analysis/LazyValueInfo.cpp @@ -1002,7 +1002,14 @@ bool LazyValueInfoCache::solveBlockValueSelect(LVILatticeVal &BBLV, bool LazyValueInfoCache::solveBlockValueCast(LVILatticeVal &BBLV, Instruction *BBI, - BasicBlock *BB) { + BasicBlock *BB) { + if (!BBI->getOperand(0)->getType()->isSized()) { + // Without knowing how wide the input is, we can't analyze it in any useful + // way. + BBLV.markOverdefined(); + return true; + } + // Figure out the range of the LHS. If that fails, we still apply the // transfer rule on the full set since we may be able to locally infer // interesting facts. @@ -1012,14 +1019,7 @@ bool LazyValueInfoCache::solveBlockValueCast(LVILatticeVal &BBLV, return false; const unsigned OperandBitWidth = - BBI->getOperand(0)->getType()->getPrimitiveSizeInBits(); - if (OperandBitWidth == 0) { - // Without knowing how wide the input is, we can't analyze it in any useful - // way. - BBLV.markOverdefined(); - return true; - } - + DL.getTypeSizeInBits(BBI->getOperand(0)->getType()); ConstantRange LHSRange = ConstantRange(OperandBitWidth); if (hasBlockValue(BBI->getOperand(0), BB)) { LVILatticeVal LHSVal = getBlockValue(BBI->getOperand(0), BB); @@ -1062,7 +1062,8 @@ bool LazyValueInfoCache::solveBlockValueCast(LVILatticeVal &BBLV, bool LazyValueInfoCache::solveBlockValueBinaryOp(LVILatticeVal &BBLV, Instruction *BBI, - BasicBlock *BB) { + BasicBlock *BB) { + // Figure out the range of the LHS. If that fails, bail. if (!hasBlockValue(BBI->getOperand(0), BB)) { if (pushBlockValue(std::make_pair(BB, BBI->getOperand(0)))) diff --git a/test/Transforms/CorrelatedValuePropagation/basic.ll b/test/Transforms/CorrelatedValuePropagation/basic.ll index 0112d489760..9f41807cc55 100644 --- a/test/Transforms/CorrelatedValuePropagation/basic.ll +++ b/test/Transforms/CorrelatedValuePropagation/basic.ll @@ -429,3 +429,14 @@ entry: exit: ret i1 %cmp } + +define i1 @bitcast_unknown2(i8* %p) { +; CHECK-LABEL: @bitcast_unknown2 +; CHECK: ret i1 %cmp +entry: + %p64 = ptrtoint i8* %p to i64 + %cmp = icmp sle i64 %p64, 128 + br label %exit +exit: + ret i1 %cmp +} -- 2.11.0