Skip to content

Commit

Permalink
[ConstraintElimination] Fix sign of sub decomposition.
Browse files Browse the repository at this point in the history
Update the decomposition code to make sure the right coefficient (-1) is
used for the second operand of the subtract.

Fixes PR53123.
  • Loading branch information
fhahn committed Jan 24, 2022
1 parent 830df62 commit 8a15caa
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 2 deletions.
2 changes: 1 addition & 1 deletion llvm/lib/Transforms/Scalar/ConstraintElimination.cpp
Expand Up @@ -108,7 +108,7 @@ static SmallVector<std::pair<int64_t, Value *>, 4> decompose(Value *V) {
if (match(V, m_NUWSub(m_Value(Op0), m_ConstantInt(CI))))
return {{-1 * CI->getSExtValue(), nullptr}, {1, Op0}};
if (match(V, m_NUWSub(m_Value(Op0), m_Value(Op1))))
return {{0, nullptr}, {1, Op0}, {1, Op1}};
return {{0, nullptr}, {1, Op0}, {-1, Op1}};

return {{0, nullptr}, {1, V}};
}
Expand Down
2 changes: 1 addition & 1 deletion llvm/test/Transforms/ConstraintElimination/sub-nuw.ll
Expand Up @@ -247,7 +247,7 @@ define i16 @test_pr53123_sub_constraint_sign(i16 %v) {
; CHECK-NEXT: [[ADD:%.*]] = shl nuw nsw i16 [[V]], 1
; CHECK-NEXT: [[SUB9:%.*]] = sub nuw nsw i16 32767, [[ADD]]
; CHECK-NEXT: [[CMP11:%.*]] = icmp ugt i16 [[ADD]], [[SUB9]]
; CHECK-NEXT: br i1 false, label [[BB_3:%.*]], label [[BB_2]]
; CHECK-NEXT: br i1 [[CMP11]], label [[BB_3:%.*]], label [[BB_2]]
; CHECK: bb.2:
; CHECK-NEXT: ret i16 1
; CHECK: bb.3:
Expand Down

0 comments on commit 8a15caa

Please sign in to comment.