[llvm] [IR] Add support for `samesign` in `Operator::hasPoisonGeneratingFlags` (PR #112358)
via llvm-commits
llvm-commits at lists.llvm.org
Tue Oct 15 06:42:43 PDT 2024
llvmbot wrote:
<!--LLVM PR SUMMARY COMMENT-->
@llvm/pr-subscribers-llvm-ir
@llvm/pr-subscribers-llvm-transforms
Author: Yingwei Zheng (dtcxzyw)
<details>
<summary>Changes</summary>
Fix https://github.com/llvm/llvm-project/issues/112356. Sorry about that...
---
Full diff: https://github.com/llvm/llvm-project/pull/112358.diff
2 Files Affected:
- (modified) llvm/lib/IR/Operator.cpp (+2)
- (modified) llvm/test/Transforms/InstCombine/icmp.ll (+11)
``````````diff
diff --git a/llvm/lib/IR/Operator.cpp b/llvm/lib/IR/Operator.cpp
index f93ff8f6fc8a25..199eb4d90f5565 100644
--- a/llvm/lib/IR/Operator.cpp
+++ b/llvm/lib/IR/Operator.cpp
@@ -50,6 +50,8 @@ bool Operator::hasPoisonGeneratingFlags() const {
if (auto *NNI = dyn_cast<PossiblyNonNegInst>(this))
return NNI->hasNonNeg();
return false;
+ case Instruction::ICmp:
+ return cast<ICmpInst>(this)->hasSameSign();
default:
if (const auto *FP = dyn_cast<FPMathOperator>(this))
return FP->hasNoNaNs() || FP->hasNoInfs();
diff --git a/llvm/test/Transforms/InstCombine/icmp.ll b/llvm/test/Transforms/InstCombine/icmp.ll
index ecf21b8a42cf50..bfe70f992b8457 100644
--- a/llvm/test/Transforms/InstCombine/icmp.ll
+++ b/llvm/test/Transforms/InstCombine/icmp.ll
@@ -5365,3 +5365,14 @@ define i1 @icmp_and_inv_pow2_or_zero_ne_0(i32 %A, i32 %B) {
%cmp = icmp ne i32 %and, 0
ret i1 %cmp
}
+
+define i1 @icmp_samesign_logical_and(i32 %In) {
+; CHECK-LABEL: @icmp_samesign_logical_and(
+; CHECK-NEXT: [[C2:%.*]] = icmp eq i32 [[IN:%.*]], 1
+; CHECK-NEXT: ret i1 [[C2]]
+;
+ %c1 = icmp samesign sgt i32 %In, -1
+ %c2 = icmp samesign eq i32 %In, 1
+ %V = select i1 %c1, i1 %c2, i1 false
+ ret i1 %V
+}
``````````
</details>
https://github.com/llvm/llvm-project/pull/112358
More information about the llvm-commits
mailing list