Skip to content

Commit 2f587c3

Browse files
committed
[IndVarSimplify] Drop samesame flags after narrowing compares
1 parent 064bfdd commit 2f587c3

File tree

2 files changed

+3
-1
lines changed

2 files changed

+3
-1
lines changed

llvm/lib/Transforms/Scalar/IndVarSimplify.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1530,6 +1530,8 @@ bool IndVarSimplify::canonicalizeExitCondition(Loop *L) {
15301530
L->getLoopPreheader()->getTerminator()->getIterator());
15311531
ICmp->setOperand(Swapped ? 1 : 0, LHSOp);
15321532
ICmp->setOperand(Swapped ? 0 : 1, NewRHS);
1533+
// Samesign flag cannot be preserved after narrowing the compare.
1534+
ICmp->setSameSign(false);
15331535
if (LHS->use_empty())
15341536
DeadInsts.push_back(LHS);
15351537
};

llvm/test/Transforms/IndVarSimplify/finite-exit-comparisons.ll

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1064,7 +1064,7 @@ define i8 @test_drop_icmp_samesign(i1 %cond, i32 range(i32 0, 32) %x) {
10641064
; CHECK-NEXT: br label [[EXIT:%.*]]
10651065
; CHECK: for.body:
10661066
; CHECK-NEXT: [[CALL2:%.*]] = call i8 @callee()
1067-
; CHECK-NEXT: [[COND2:%.*]] = icmp samesign ugt i8 [[TMP0]], [[CALL2]]
1067+
; CHECK-NEXT: [[COND2:%.*]] = icmp ugt i8 [[TMP0]], [[CALL2]]
10681068
; CHECK-NEXT: br i1 [[COND2]], label [[FOR_BODY]], label [[EXIT_LOOPEXIT:%.*]]
10691069
; CHECK: exit.loopexit:
10701070
; CHECK-NEXT: [[CALL2_LCSSA:%.*]] = phi i8 [ [[CALL2]], [[FOR_BODY]] ]

0 commit comments

Comments
 (0)