[llvm] [InstCombine] Add Missed Optimization (PR #141962)
via llvm-commits
llvm-commits at lists.llvm.org
Thu May 29 08:17:20 PDT 2025
llvmbot wrote:
<!--LLVM PR SUMMARY COMMENT-->
@llvm/pr-subscribers-llvm-transforms
Author: Bobby SONG (bobby-b-song)
<details>
<summary>Changes</summary>
Addresses the https://github.com/llvm/llvm-project/issues/141479 issue. By adding the following optimiztion
```
define i1 @<!-- -->src(i32 %0, i32 %1) local_unnamed_addr #<!-- -->0 {
common.ret:
%2 = xor i32 %0, -1
%3 = icmp ule i32 %1, %2
%4 = xor i32 %1, -1
%5 = icmp ugt i32 %0, %4
%common.ret.op = and i1 %3, %5
ret i1 %common.ret.op
}
```
to
```
define noundef i1 @<!-- -->tgt(i32 %0, i32 %1) local_unnamed_addr #<!-- -->0 {
common.ret:
ret i1 false
}
```
---
Full diff: https://github.com/llvm/llvm-project/pull/141962.diff
1 Files Affected:
- (added) llvm/test/Transforms/InstCombine/and-comparison-not-always-false.ll (+21)
``````````diff
diff --git a/llvm/test/Transforms/InstCombine/and-comparison-not-always-false.ll b/llvm/test/Transforms/InstCombine/and-comparison-not-always-false.ll
new file mode 100644
index 0000000000000..174d97d30bcf8
--- /dev/null
+++ b/llvm/test/Transforms/InstCombine/and-comparison-not-always-false.ll
@@ -0,0 +1,21 @@
+; NOTE: Assertions have been autogenerated by utils/update_test_checks.py UTC_ARGS: --version 5
+; RUN: opt < %s -passes=instcombine -S | FileCheck %s
+define i1 @test(i32 %0, i32 %1) {
+; CHECK-LABEL: define i1 @test(
+; CHECK-SAME: i32 [[TMP0:%.*]], i32 [[TMP1:%.*]]) {
+; CHECK-NEXT: [[COMMON_RET:.*:]]
+; CHECK-NEXT: [[TMP2:%.*]] = xor i32 [[TMP0]], -1
+; CHECK-NEXT: [[TMP3:%.*]] = icmp ule i32 [[TMP1]], [[TMP2]]
+; CHECK-NEXT: [[TMP4:%.*]] = xor i32 [[TMP1]], -1
+; CHECK-NEXT: [[TMP5:%.*]] = icmp ugt i32 [[TMP0]], [[TMP4]]
+; CHECK-NEXT: [[COMMON_RET_OP:%.*]] = and i1 [[TMP3]], [[TMP5]]
+; CHECK-NEXT: ret i1 [[COMMON_RET_OP]]
+;
+common.ret:
+ %2 = xor i32 %0, -1
+ %3 = icmp ule i32 %1, %2
+ %4 = xor i32 %1, -1
+ %5 = icmp ugt i32 %0, %4
+ %common.ret.op = and i1 %3, %5
+ ret i1 %common.ret.op
+}
``````````
</details>
https://github.com/llvm/llvm-project/pull/141962
More information about the llvm-commits
mailing list