[PATCH] D131140: [NFC][InstCombine] Add baseline tests for canonicalizing ((x + C1) & C2) --> ((x & C2) + C1) ((x + C1) ^ C2) --> ((x ^ C2) + C1) ((x + C1) | C2) --> ((x | C2) + C1) for suitable constants C1 and C2.
Eric Gullufsen via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Wed Aug 3 21:57:00 PDT 2022
emgullufsen created this revision.
Herald added a project: All.
emgullufsen requested review of this revision.
Herald added a project: LLVM.
Herald added a subscriber: llvm-commits.
Repository:
rG LLVM Github Monorepo
https://reviews.llvm.org/D131140
Files:
llvm/test/Transforms/InstCombine/and-xor-or.ll
Index: llvm/test/Transforms/InstCombine/and-xor-or.ll
===================================================================
--- llvm/test/Transforms/InstCombine/and-xor-or.ll
+++ llvm/test/Transforms/InstCombine/and-xor-or.ll
@@ -4355,3 +4355,75 @@
%t7 = icmp ne i32 %t6, 0
ret i1 %t7
}
+
+define i32 @canonicalize_logic_first_or_0(i32 %x) {
+; CHECK-LABEL: define {{[^@]+}}@canonicalize_logic_first_or_0
+; CHECK-SAME: (i32 [[X:%.*]]) {
+; CHECK-NEXT: [[A:%.*]] = add i32 [[X]], 112
+; CHECK-NEXT: [[R:%.*]] = or i32 [[A]], 15
+; CHECK-NEXT: ret i32 [[R]]
+;
+ %a = add i32 %x, 112 ; 01110000
+ %r = or i32 %a, 15 ; 00001111
+ ret i32 %r
+}
+
+define i32 @canonicalize_logic_first_negative_or_0(i32 %x) {
+; CHECK-LABEL: define {{[^@]+}}@canonicalize_logic_first_negative_or_0
+; CHECK-SAME: (i32 [[X:%.*]]) {
+; CHECK-NEXT: [[A:%.*]] = add i32 [[X]], 112
+; CHECK-NEXT: [[R:%.*]] = or i32 [[A]], 16
+; CHECK-NEXT: ret i32 [[R]]
+;
+ %a = add i32 %x, 112 ; 01110000
+ %r = or i32 %a, 16 ; 00010000
+ ret i32 %r
+}
+
+define i8 @canonicalize_logic_first_and_0(i8 %x) {
+; CHECK-LABEL: define {{[^@]+}}@canonicalize_logic_first_and_0
+; CHECK-SAME: (i8 [[X:%.*]]) {
+; CHECK-NEXT: [[B:%.*]] = add i8 [[X]], 48
+; CHECK-NEXT: [[R:%.*]] = and i8 [[B]], -10
+; CHECK-NEXT: ret i8 [[R]]
+;
+ %b = add i8 %x, 48 ; 00110000
+ %r = and i8 %b, -10 ; 11110110
+ ret i8 %r
+}
+
+define i8 @canonicalize_logic_first_negative_and_0(i8 %x) {
+; CHECK-LABEL: define {{[^@]+}}@canonicalize_logic_first_negative_and_0
+; CHECK-SAME: (i8 [[X:%.*]]) {
+; CHECK-NEXT: [[B:%.*]] = add i8 [[X]], 48
+; CHECK-NEXT: [[R:%.*]] = and i8 [[B]], -26
+; CHECK-NEXT: ret i8 [[R]]
+;
+ %b = add i8 %x, 48 ; 00110000
+ %r = and i8 %b, -26 ; 11100110
+ ret i8 %r
+}
+
+define i8 @canonicalize_logic_first_xor_0(i8 %x) {
+; CHECK-LABEL: define {{[^@]+}}@canonicalize_logic_first_xor_0
+; CHECK-SAME: (i8 [[X:%.*]]) {
+; CHECK-NEXT: [[A:%.*]] = add i8 [[X]], 96
+; CHECK-NEXT: [[R:%.*]] = xor i8 [[A]], 31
+; CHECK-NEXT: ret i8 [[R]]
+;
+ %a = add i8 %x, 96 ; 01100000
+ %r = xor i8 %a, 31 ; 00011111
+ ret i8 %r
+}
+
+define i8 @canonicalize_logic_first_negative_xor_0(i8 %x) {
+; CHECK-LABEL: define {{[^@]+}}@canonicalize_logic_first_negative_xor_0
+; CHECK-SAME: (i8 [[X:%.*]]) {
+; CHECK-NEXT: [[A:%.*]] = add i8 [[X]], 96
+; CHECK-NEXT: [[R:%.*]] = xor i8 [[A]], 32
+; CHECK-NEXT: ret i8 [[R]]
+;
+ %a = add i8 %x, 96 ; 01100000
+ %r = xor i8 %a, 32 ; 00100000
+ ret i8 %r
+}
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D131140.449873.patch
Type: text/x-patch
Size: 2546 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20220804/bad1977b/attachment.bin>
More information about the llvm-commits
mailing list