Skip to content

Commit 1264d23

Browse files
committed
[ConstraintElim] Check the other signedness when hasSameSign
1 parent a500703 commit 1264d23

File tree

2 files changed

+10
-5
lines changed

2 files changed

+10
-5
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() && Cmp->isRelational())
1465+
if (auto ImpliedCondition =
1466+
checkCondition(Cmp->getFlippedSignednessPredicate(),
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: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -309,8 +309,7 @@ define i1 @samesign_flipped_signedness_1(i8 %a, i8 %b) {
309309
; CHECK-NEXT: [[CMP_UGT:%.*]] = icmp ugt i8 [[A:%.*]], [[B:%.*]]
310310
; CHECK-NEXT: br i1 [[CMP_UGT]], label [[GREATER:%.*]], label [[EXIT:%.*]]
311311
; CHECK: greater:
312-
; CHECK-NEXT: [[CMP_SGT:%.*]] = icmp samesign sgt i8 [[A]], [[B]]
313-
; CHECK-NEXT: ret i1 [[CMP_SGT]]
312+
; CHECK-NEXT: ret i1 true
314313
; CHECK: exit:
315314
; CHECK-NEXT: ret i1 false
316315
;
@@ -332,8 +331,7 @@ define i1 @samesign_flipped_signedness_2(i32 %a) {
332331
; CHECK: for.cond.preheader:
333332
; CHECK-NEXT: ret i1 false
334333
; CHECK: if.else:
335-
; CHECK-NEXT: [[CMP_UGT:%.*]] = icmp samesign ugt i32 [[A]], -65
336-
; CHECK-NEXT: ret i1 [[CMP_UGT]]
334+
; CHECK-NEXT: ret i1 true
337335
;
338336
%cmp_ult = icmp samesign ult i32 %a, 65
339337
br i1 %cmp_ult, label %for.cond.preheader, label %if.else

0 commit comments

Comments
 (0)