Skip to content

Commit 7cce3e7

Browse files
committed
[LVI] Support no constant range of cast and freeze value in getEdgeValueLocal.
1 parent 3b6e08d commit 7cce3e7

File tree

3 files changed

+24
-6
lines changed

3 files changed

+24
-6
lines changed

llvm/lib/Analysis/LazyValueInfo.cpp

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1493,6 +1493,24 @@ LazyValueInfoImpl::getEdgeValueLocal(Value *Val, BasicBlock *BBFrom,
14931493
// br %Condition, label %then, label %else
14941494
APInt ConditionVal(1, isTrueDest ? 1 : 0);
14951495
Result = constantFoldUser(Usr, Condition, ConditionVal, DL);
1496+
} else if (isa<TruncInst, ZExtInst, SExtInst, FreezeInst>(Usr)) {
1497+
ValueLatticeElement OpLatticeVal =
1498+
*getValueFromCondition(Usr->getOperand(0), Condition,
1499+
isTrueDest, /*UseBlockValue*/ false);
1500+
1501+
if (isa<FreezeInst>(Usr) || !OpLatticeVal.isConstantRange())
1502+
return OpLatticeVal;
1503+
1504+
const unsigned ResultBitWidth =
1505+
Usr->getType()->getScalarSizeInBits();
1506+
if (auto *Trunc = dyn_cast<TruncInst>(Usr))
1507+
return ValueLatticeElement::getRange(
1508+
OpLatticeVal.getConstantRange().truncate(
1509+
ResultBitWidth, Trunc->getNoWrapKind()));
1510+
1511+
return ValueLatticeElement::getRange(
1512+
OpLatticeVal.getConstantRange().castOp(
1513+
cast<CastInst>(Usr)->getOpcode(), ResultBitWidth));
14961514
} else {
14971515
// If one of Val's operand has an inferred value, we may be able to
14981516
// infer the value of Val.

llvm/test/Transforms/CorrelatedValuePropagation/range.ll

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1236,7 +1236,7 @@ define i1 @neg_icmp_eq_range_call() {
12361236
}
12371237

12381238
define i16 @return_range_for_edge_value_zext(i8 %a) {
1239-
; CHECK-LABEL: define range(i16 0, 256) i16 @return_range_for_edge_value_zext(
1239+
; CHECK-LABEL: define range(i16 0, 98) i16 @return_range_for_edge_value_zext(
12401240
; CHECK-SAME: i8 [[A:%.*]]) {
12411241
; CHECK-NEXT: [[ENTRY:.*:]]
12421242
; CHECK-NEXT: [[B:%.*]] = zext i8 [[A]] to i16
@@ -1260,7 +1260,7 @@ target:
12601260
}
12611261

12621262
define i16 @return_range_for_edge_value_sext(i8 %a) {
1263-
; CHECK-LABEL: define range(i16 -128, 128) i16 @return_range_for_edge_value_sext(
1263+
; CHECK-LABEL: define range(i16 0, 98) i16 @return_range_for_edge_value_sext(
12641264
; CHECK-SAME: i8 [[A:%.*]]) {
12651265
; CHECK-NEXT: [[ENTRY:.*:]]
12661266
; CHECK-NEXT: [[B:%.*]] = sext i8 [[A]] to i16
@@ -1284,7 +1284,7 @@ target:
12841284
}
12851285

12861286
define i8 @return_range_for_edge_value_trunc(i16 %a) {
1287-
; CHECK-LABEL: define i8 @return_range_for_edge_value_trunc(
1287+
; CHECK-LABEL: define range(i8 0, 98) i8 @return_range_for_edge_value_trunc(
12881288
; CHECK-SAME: i16 [[A:%.*]]) {
12891289
; CHECK-NEXT: [[ENTRY:.*:]]
12901290
; CHECK-NEXT: [[B:%.*]] = trunc i16 [[A]] to i8
@@ -1332,7 +1332,7 @@ target:
13321332
}
13331333

13341334
define i8 @return_range_for_edge_value_trunc_nuw(i16 %a) {
1335-
; CHECK-LABEL: define i8 @return_range_for_edge_value_trunc_nuw(
1335+
; CHECK-LABEL: define range(i8 -55, 0) i8 @return_range_for_edge_value_trunc_nuw(
13361336
; CHECK-SAME: i16 [[A:%.*]]) {
13371337
; CHECK-NEXT: [[ENTRY:.*:]]
13381338
; CHECK-NEXT: [[B:%.*]] = trunc nuw i16 [[A]] to i8
@@ -1356,7 +1356,7 @@ target:
13561356
}
13571357

13581358
define i8 @return_range_for_edge_value_freeze(i8 %a) {
1359-
; CHECK-LABEL: define i8 @return_range_for_edge_value_freeze(
1359+
; CHECK-LABEL: define range(i8 0, 98) i8 @return_range_for_edge_value_freeze(
13601360
; CHECK-SAME: i8 [[A:%.*]]) {
13611361
; CHECK-NEXT: [[ENTRY:.*:]]
13621362
; CHECK-NEXT: [[B:%.*]] = freeze i8 [[A]]

llvm/test/Transforms/JumpThreading/branch-debug-info2.ll

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ if.end.i60: ; preds = %shadow_to_ptr.exit
1919
; Jump threading is going to fold the select in to the branch. Ensure debug
2020
; info is not lost, and is merged from the select and the branch.
2121
; CHECK-NOT: br i1 %cmp3.i, label %for.inc, label %ptr_to_shadow.exit
22-
; CHECK: br i1 %cmp3.i, label %for.inc, label %ptr_to_shadow.exit, !dbg [[DBG:![0-9]+]]
22+
; CHECK: br i1 %cmp3.i, label %for.inc, label %if.end22, !dbg [[DBG:![0-9]+]]
2323
; CHECK: [[DBG]] = !DILocation(line: 9, column: 1, scope: !{{.*}})
2424

2525
br label %ptr_to_shadow.exit, !dbg !17

0 commit comments

Comments
 (0)