Skip to content

Commit e870846

Browse files
dtcxzywDanielCChen
authored andcommitted
[IR] Add support for samesign in Operator::hasPoisonGeneratingFlags (llvm#112358)
Fix llvm#112356.
1 parent 318b93f commit e870846

File tree

2 files changed

+24
-0
lines changed

2 files changed

+24
-0
lines changed

llvm/lib/IR/Operator.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,8 @@ bool Operator::hasPoisonGeneratingFlags() const {
5050
if (auto *NNI = dyn_cast<PossiblyNonNegInst>(this))
5151
return NNI->hasNonNeg();
5252
return false;
53+
case Instruction::ICmp:
54+
return cast<ICmpInst>(this)->hasSameSign();
5355
default:
5456
if (const auto *FP = dyn_cast<FPMathOperator>(this))
5557
return FP->hasNoNaNs() || FP->hasNoInfs();

llvm/test/Transforms/InstCombine/icmp.ll

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5365,3 +5365,25 @@ define i1 @icmp_and_inv_pow2_or_zero_ne_0(i32 %A, i32 %B) {
53655365
%cmp = icmp ne i32 %and, 0
53665366
ret i1 %cmp
53675367
}
5368+
5369+
define i1 @icmp_samesign_logical_and(i32 %In) {
5370+
; CHECK-LABEL: @icmp_samesign_logical_and(
5371+
; CHECK-NEXT: [[C2:%.*]] = icmp eq i32 [[IN:%.*]], 1
5372+
; CHECK-NEXT: ret i1 [[C2]]
5373+
;
5374+
%c1 = icmp samesign sgt i32 %In, -1
5375+
%c2 = icmp samesign eq i32 %In, 1
5376+
%V = select i1 %c1, i1 %c2, i1 false
5377+
ret i1 %V
5378+
}
5379+
5380+
define i1 @icmp_samesign_logical_or(i32 %In) {
5381+
; CHECK-LABEL: @icmp_samesign_logical_or(
5382+
; CHECK-NEXT: [[V:%.*]] = icmp ne i32 [[IN:%.*]], 1
5383+
; CHECK-NEXT: ret i1 [[V]]
5384+
;
5385+
%c1 = icmp samesign slt i32 %In, 0
5386+
%c2 = icmp samesign ne i32 %In, 1
5387+
%V = select i1 %c1, i1 true, i1 %c2
5388+
ret i1 %V
5389+
}

0 commit comments

Comments
 (0)