Skip to content

Commit d5db2cd

Browse files
committed
[LVI] Don't push both binop operands at once
If one of the binop operands depends on the other, this may end up evaluating them in the wrong order, producing sub-optimal results. Make sure that only one unevaluated operand gets pushed per iteration. Fixes #76705.
1 parent aa6bb16 commit d5db2cd

File tree

2 files changed

+5
-4
lines changed

2 files changed

+5
-4
lines changed

llvm/lib/Analysis/LazyValueInfo.cpp

+4-2
Original file line numberDiff line numberDiff line change
@@ -976,9 +976,11 @@ LazyValueInfoImpl::solveBlockValueBinaryOpImpl(
976976
// lets us pick up facts from expressions like "and i32 (call i32
977977
// @foo()), 32"
978978
std::optional<ConstantRange> LHSRes = getRangeFor(I->getOperand(0), I, BB);
979+
if (!LHSRes)
980+
return std::nullopt;
981+
979982
std::optional<ConstantRange> RHSRes = getRangeFor(I->getOperand(1), I, BB);
980-
if (!LHSRes || !RHSRes)
981-
// More work to do before applying this transfer rule.
983+
if (!RHSRes)
982984
return std::nullopt;
983985

984986
const ConstantRange &LHSRange = *LHSRes;

llvm/test/Transforms/CorrelatedValuePropagation/basic.ll

+1-2
Original file line numberDiff line numberDiff line change
@@ -1915,8 +1915,7 @@ define i1 @binop_eval_order(i32 %x) {
19151915
; CHECK-NEXT: [[A:%.*]] = add nuw nsw i32 [[X:%.*]], 1
19161916
; CHECK-NEXT: [[B:%.*]] = add nuw nsw i32 [[A]], 1
19171917
; CHECK-NEXT: [[C:%.*]] = add nuw nsw i32 [[A]], [[B]]
1918-
; CHECK-NEXT: [[D:%.*]] = icmp ugt i32 [[C]], 2
1919-
; CHECK-NEXT: ret i1 [[D]]
1918+
; CHECK-NEXT: ret i1 true
19201919
;
19211920
%a = add nuw nsw i32 %x, 1
19221921
%b = add nuw nsw i32 %a, 1

0 commit comments

Comments
 (0)