Skip to content

Commit f6d4148

Browse files
committed
[ConstraintElimination] Fix sign of sub decomposition.
Update the decomposition code to make sure the right coefficient (-1) is used for the second operand of the subtract. Fixes PR53123. (cherry-picked from 8a15caa)
1 parent cdd08a7 commit f6d4148

File tree

2 files changed

+2
-2
lines changed

2 files changed

+2
-2
lines changed

llvm/lib/Transforms/Scalar/ConstraintElimination.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@ static SmallVector<std::pair<int64_t, Value *>, 4> decompose(Value *V) {
108108
if (match(V, m_NUWSub(m_Value(Op0), m_ConstantInt(CI))))
109109
return {{-1 * CI->getSExtValue(), nullptr}, {1, Op0}};
110110
if (match(V, m_NUWSub(m_Value(Op0), m_Value(Op1))))
111-
return {{0, nullptr}, {1, Op0}, {1, Op1}};
111+
return {{0, nullptr}, {1, Op0}, {-1, Op1}};
112112

113113
return {{0, nullptr}, {1, V}};
114114
}

llvm/test/Transforms/ConstraintElimination/sub-nuw.ll

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -247,7 +247,7 @@ define i16 @test_pr53123_sub_constraint_sign(i16 %v) {
247247
; CHECK-NEXT: [[ADD:%.*]] = shl nuw nsw i16 [[V]], 1
248248
; CHECK-NEXT: [[SUB9:%.*]] = sub nuw nsw i16 32767, [[ADD]]
249249
; CHECK-NEXT: [[CMP11:%.*]] = icmp ugt i16 [[ADD]], [[SUB9]]
250-
; CHECK-NEXT: br i1 false, label [[BB_3:%.*]], label [[BB_2]]
250+
; CHECK-NEXT: br i1 [[CMP11]], label [[BB_3:%.*]], label [[BB_2]]
251251
; CHECK: bb.2:
252252
; CHECK-NEXT: ret i16 1
253253
; CHECK: bb.3:

0 commit comments

Comments
 (0)