[llvm] [InstCombine] Reducing rust i128::midpoint instructions (PR #99614)
via llvm-commits
llvm-commits at lists.llvm.org
Fri Jul 19 01:19:19 PDT 2024
llvmbot wrote:
<!--LLVM PR SUMMARY COMMENT-->
@llvm/pr-subscribers-llvm-transforms
Author: Julius Alexandre (medievalghoul)
<details>
<summary>Changes</summary>
**Issue**: https://github.com/rust-lang/rust/issues/124790
This seems to only affect `u128` data types
https://alive2.llvm.org/ce/z/QmFkhy
https://rust.godbolt.org/z/T7eKP3Tvo
---
Full diff: https://github.com/llvm/llvm-project/pull/99614.diff
1 Files Affected:
- (added) llvm/test/Transforms/InstCombine/xor_lshr_and_i128.ll (+142)
``````````diff
diff --git a/llvm/test/Transforms/InstCombine/xor_lshr_and_i128.ll b/llvm/test/Transforms/InstCombine/xor_lshr_and_i128.ll
new file mode 100644
index 0000000000000..a219a945722d7
--- /dev/null
+++ b/llvm/test/Transforms/InstCombine/xor_lshr_and_i128.ll
@@ -0,0 +1,142 @@
+; NOTE: Assertions have been autogenerated by utils/update_test_checks.py UTC_ARGS: --version 5
+; RUN: opt < %s -passes=instcombine -S | FileCheck %s
+
+define noundef i128 @xor_lshr_and(i128 noundef %x, i128 noundef %y) unnamed_addr #0 {
+; check-label: define noundef i128 @xor_lshr_and(
+; check-same: i128 noundef [[x:%.*]], i128 noundef [[y:%.*]]) unnamed_addr {
+; check-next: [[start:.*:]]
+; check-next: [[xor:%.*]] = xor i128 [[y]], [[x]]
+; check-next: [[lshr:%.*]] = lshr i128 [[xor]], 1
+; check-next: [[and:%.*]] = and i128 [[y]], [[x]]
+; check-next: [[add:%.*]] = add i128 [[lshr]], [[and]]
+; check-next: ret i128 [[add]]
+;
+; CHECK-LABEL: define noundef i128 @xor_lshr_and(
+; CHECK-SAME: i128 noundef [[X:%.*]], i128 noundef [[Y:%.*]]) unnamed_addr {
+; CHECK-NEXT: [[START:.*:]]
+; CHECK-NEXT: [[XOR:%.*]] = xor i128 [[Y]], [[X]]
+; CHECK-NEXT: [[LSHR:%.*]] = lshr i128 [[XOR]], 1
+; CHECK-NEXT: [[AND:%.*]] = and i128 [[Y]], [[X]]
+; CHECK-NEXT: [[ADD:%.*]] = add i128 [[LSHR]], [[AND]]
+; CHECK-NEXT: ret i128 [[ADD]]
+;
+start:
+ %xor = xor i128 %y, %x
+ %lshr = lshr i128 %xor, 1
+ %and = and i128 %y, %x
+ %add = add i128 %lshr, %and
+ ret i128 %add
+}
+
+define noundef i128 @xor_lshr_and_commuted1(i128 noundef %x, i128 noundef %y) unnamed_addr #0 {
+; CHECK-LABEL: define noundef i128 @xor_lshr_and_commuted1(
+; CHECK-SAME: i128 noundef [[X:%.*]], i128 noundef [[Y:%.*]]) unnamed_addr {
+; CHECK-NEXT: [[START:.*:]]
+; CHECK-NEXT: [[AND:%.*]] = and i128 [[Y]], [[X]]
+; CHECK-NEXT: [[XOR:%.*]] = xor i128 [[Y]], [[X]]
+; CHECK-NEXT: [[LSHR:%.*]] = lshr i128 [[XOR]], 1
+; CHECK-NEXT: [[ADD:%.*]] = add i128 [[LSHR]], [[AND]]
+; CHECK-NEXT: ret i128 [[ADD]]
+;
+start:
+ %and = and i128 %y, %x
+ %xor = xor i128 %y, %x
+ %lshr = lshr i128 %xor, 1
+ %add = add i128 %lshr, %and
+ ret i128 %add
+}
+
+define noundef i128 @xor_lshr_and_commuted2(i128 noundef %x, i128 noundef %y) unnamed_addr #0 {
+; CHECK-LABEL: define noundef i128 @xor_lshr_and_commuted2(
+; CHECK-SAME: i128 noundef [[X:%.*]], i128 noundef [[Y:%.*]]) unnamed_addr {
+; CHECK-NEXT: [[START:.*:]]
+; CHECK-NEXT: [[AND:%.*]] = and i128 [[Y]], [[X]]
+; CHECK-NEXT: [[XOR:%.*]] = xor i128 [[Y]], [[X]]
+; CHECK-NEXT: [[LSHR:%.*]] = lshr i128 [[XOR]], 1
+; CHECK-NEXT: [[ADD:%.*]] = add i128 [[LSHR]], [[AND]]
+; CHECK-NEXT: ret i128 [[ADD]]
+;
+start:
+ %and = and i128 %y, %x
+ %xor = xor i128 %y, %x
+ %lshr = lshr i128 %xor, 1
+ %add = add i128 %lshr, %and
+ ret i128 %add
+}
+
+declare void @use(i8)
+
+define noundef i128 @xor_lshr_and_multi_use(i128 noundef %x, i128 noundef %y) unnamed_addr #0 {
+; CHECK-LABEL: define noundef i128 @xor_lshr_and_multi_use(
+; CHECK-SAME: i128 noundef [[X:%.*]], i128 noundef [[Y:%.*]]) unnamed_addr {
+; CHECK-NEXT: [[START:.*:]]
+; CHECK-NEXT: [[XOR:%.*]] = xor i128 [[Y]], [[X]]
+; CHECK-NEXT: call void @use(i128 [[XOR]])
+; CHECK-NEXT: [[LSHR:%.*]] = lshr i128 [[XOR]], 1
+; CHECK-NEXT: call void @use(i128 [[LSHR]])
+; CHECK-NEXT: [[AND:%.*]] = and i128 [[Y]], [[X]]
+; CHECK-NEXT: [[ADD:%.*]] = add i128 [[LSHR]], [[AND]]
+; CHECK-NEXT: ret i128 [[ADD]]
+;
+start:
+ %xor = xor i128 %y, %x
+ call void @use(i128 %xor)
+ %lshr = lshr i128 %xor, 1
+ call void @use(i128 %lshr)
+ %and = and i128 %y, %x
+ %add = add i128 %lshr, %and
+ ret i128 %add
+}
+
+define noundef i128 @xor_lshr_and_negative(i128 noundef %x, i128 noundef %y) unnamed_addr #0 {
+; CHECK-LABEL: define noundef i128 @xor_lshr_and_negative(
+; CHECK-SAME: i128 noundef [[X:%.*]], i128 noundef [[Y:%.*]]) unnamed_addr {
+; CHECK-NEXT: [[START:.*:]]
+; CHECK-NEXT: [[XOR:%.*]] = xor i128 [[X]], -1
+; CHECK-NEXT: [[AND:%.*]] = and i128 [[Y]], [[X]]
+; CHECK-NEXT: [[ADD:%.*]] = add i128 [[AND]], [[XOR]]
+; CHECK-NEXT: ret i128 [[ADD]]
+;
+start:
+ %xor = xor i128 %x, -1
+ %and = and i128 %y, %x
+ %add = add i128 %xor, %and
+ ret i128 %add
+}
+
+define noundef i32 @xor_lshr_and_negative2(i32 noundef %x, i32 noundef %y) unnamed_addr #0 {
+; CHECK-LABEL: define noundef i32 @xor_lshr_and_negative2(
+; CHECK-SAME: i32 noundef [[X:%.*]], i32 noundef [[Y:%.*]]) unnamed_addr {
+; CHECK-NEXT: [[START:.*:]]
+; CHECK-NEXT: [[XOR:%.*]] = xor i32 [[Y]], [[X]]
+; CHECK-NEXT: [[LSHR:%.*]] = lshr i32 [[XOR]], 1
+; CHECK-NEXT: [[AND:%.*]] = and i32 [[Y]], [[X]]
+; CHECK-NEXT: [[ADD:%.*]] = add i32 [[LSHR]], [[AND]]
+; CHECK-NEXT: ret i32 [[ADD]]
+;
+start:
+ %xor = xor i32 %y, %x
+ %lshr = lshr i32 %xor, 1
+ %and = and i32 %y, %x
+ %add = add i32 %lshr, %and
+ ret i32 %add
+}
+
+define noundef <2 x i128> @xor_lshr_and_vec(<2 x i128> noundef %x, <2 x i128> noundef %y) unnamed_addr #0 {
+; CHECK-LABEL: define noundef <2 x i128> @xor_lshr_and_vec(
+; CHECK-SAME: <2 x i128> noundef [[X:%.*]], <2 x i128> noundef [[Y:%.*]]) unnamed_addr {
+; CHECK-NEXT: [[START:.*:]]
+; CHECK-NEXT: [[XOR:%.*]] = xor <2 x i128> [[Y]], [[X]]
+; CHECK-NEXT: [[LSHR:%.*]] = lshr <2 x i128> [[XOR]], <i128 1, i128 1>
+; CHECK-NEXT: [[AND:%.*]] = and <2 x i128> [[Y]], [[X]]
+; CHECK-NEXT: [[ADD:%.*]] = add <2 x i128> [[LSHR]], [[AND]]
+; CHECK-NEXT: ret <2 x i128> [[ADD]]
+;
+start:
+ %xor = xor <2 x i128> %y, %x
+ %lshr = lshr <2 x i128> %xor, <i128 1, i128 1>
+ %and = and <2 x i128> %y, %x
+ %add = add <2 x i128> %lshr, %and
+ ret <2 x i128> %add
+}
+
``````````
</details>
https://github.com/llvm/llvm-project/pull/99614
More information about the llvm-commits
mailing list