Skip to content

Commit 95b8c00

Browse files
committed
[ConstraintElim] Check the other signedness when hasSameSign
1 parent db07315 commit 95b8c00

File tree

2 files changed

+9
-3
lines changed

2 files changed

+9
-3
lines changed

llvm/lib/Transforms/Scalar/ConstraintElimination.cpp

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1427,7 +1427,7 @@ static std::optional<bool> checkCondition(CmpInst::Predicate Pred, Value *A,
14271427
}
14281428

14291429
static bool checkAndReplaceCondition(
1430-
CmpInst *Cmp, ConstraintInfo &Info, unsigned NumIn, unsigned NumOut,
1430+
ICmpInst *Cmp, ConstraintInfo &Info, unsigned NumIn, unsigned NumOut,
14311431
Instruction *ContextInst, Module *ReproducerModule,
14321432
ArrayRef<ReproducerEntry> ReproducerCondStack, DominatorTree &DT,
14331433
SmallVectorImpl<Instruction *> &ToRemove) {
@@ -1460,6 +1460,13 @@ static bool checkAndReplaceCondition(
14601460
checkCondition(Cmp->getPredicate(), Cmp->getOperand(0),
14611461
Cmp->getOperand(1), Cmp, Info))
14621462
return ReplaceCmpWithConstant(Cmp, *ImpliedCondition);
1463+
1464+
if (Cmp->hasSameSign())
1465+
if (auto ImpliedCondition = checkCondition(
1466+
ICmpInst::getFlippedSignednessPredicate(Cmp->getPredicate()),
1467+
Cmp->getOperand(0), Cmp->getOperand(1), Cmp, Info))
1468+
return ReplaceCmpWithConstant(Cmp, *ImpliedCondition);
1469+
14631470
return false;
14641471
}
14651472

llvm/test/Transforms/ConstraintElimination/transfer-samesign-facts.ll

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -309,8 +309,7 @@ define i1 @samesign_flipped_signedness(i8 %a) {
309309
; CHECK-NEXT: [[TMP1:%.*]] = icmp ugt i8 [[A:%.*]], 0
310310
; CHECK-NEXT: br i1 [[TMP1]], label [[GREATER:%.*]], label [[EXIT:%.*]]
311311
; CHECK: greater:
312-
; CHECK-NEXT: [[TMP2:%.*]] = icmp samesign sgt i8 [[A]], 0
313-
; CHECK-NEXT: ret i1 [[TMP2]]
312+
; CHECK-NEXT: ret i1 true
314313
; CHECK: exit:
315314
; CHECK-NEXT: ret i1 false
316315
;

0 commit comments

Comments
 (0)