[PATCH] D148411: [InstCombine] Add tests for (select (icmp x, Cp2_0), (binop y, Cp2_1), y); NFC

Noah Goldstein via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Wed Apr 19 13:43:31 PDT 2023


goldstein.w.n updated this revision to Diff 515076.
goldstein.w.n added a comment.

Rebase


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D148411/new/

https://reviews.llvm.org/D148411

Files:
  llvm/test/Transforms/InstCombine/select-with-bitwise-ops.ll


Index: llvm/test/Transforms/InstCombine/select-with-bitwise-ops.ll
===================================================================
--- llvm/test/Transforms/InstCombine/select-with-bitwise-ops.ll
+++ llvm/test/Transforms/InstCombine/select-with-bitwise-ops.ll
@@ -1572,3 +1572,34 @@
   %cond = select i1 %b, i8 %and, i8 %or
   ret i8 %cond
 }
+
+; Tests factoring in cost of saving the `and`
+define i64 @xor_i8_to_i64_shl_save_and_eq(i8 %x, i64 %y) {
+; CHECK-LABEL: @xor_i8_to_i64_shl_save_and_eq(
+; CHECK-NEXT:    [[XX:%.*]] = and i8 [[X:%.*]], 1
+; CHECK-NEXT:    [[CMP:%.*]] = icmp eq i8 [[XX]], 0
+; CHECK-NEXT:    [[Z:%.*]] = xor i64 [[Y:%.*]], -9223372036854775808
+; CHECK-NEXT:    [[R:%.*]] = select i1 [[CMP]], i64 [[Z]], i64 [[Y]]
+; CHECK-NEXT:    ret i64 [[R]]
+;
+  %xx = and i8 %x, 1
+  %cmp = icmp eq i8 %xx, 0
+  %z = xor i64 %y, -9223372036854775808
+  %r = select i1 %cmp, i64 %z, i64 %y
+  ret i64 %r
+}
+
+define i64 @xor_i8_to_i64_shl_save_and_ne(i8 %x, i64 %y) {
+; CHECK-LABEL: @xor_i8_to_i64_shl_save_and_ne(
+; CHECK-NEXT:    [[XX:%.*]] = and i8 [[X:%.*]], 1
+; CHECK-NEXT:    [[CMP_NOT:%.*]] = icmp eq i8 [[XX]], 0
+; CHECK-NEXT:    [[Z:%.*]] = xor i64 [[Y:%.*]], -9223372036854775808
+; CHECK-NEXT:    [[R:%.*]] = select i1 [[CMP_NOT]], i64 [[Y]], i64 [[Z]]
+; CHECK-NEXT:    ret i64 [[R]]
+;
+  %xx = and i8 %x, 1
+  %cmp = icmp ne i8 %xx, 0
+  %z = xor i64 %y, -9223372036854775808
+  %r = select i1 %cmp, i64 %z, i64 %y
+  ret i64 %r
+}


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D148411.515076.patch
Type: text/x-patch
Size: 1473 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20230419/4ce7cc05/attachment.bin>


More information about the llvm-commits mailing list