[PATCH] D123430: [InstCombine][NFC] Add baseline tests for folds icmp(X) ? f(X) : C

Alexander Shaposhnikov via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Mon Apr 11 18:08:33 PDT 2022


This revision was landed with ongoing or failed builds.
This revision was automatically updated to reflect the committed changes.
Closed by commit rG0bc314fc5412: [InstCombine][NFC] Add baseline tests for folds icmp(X) ? f(X) : C (authored by alexander-shaposhnikov).

Changed prior to commit:
  https://reviews.llvm.org/D123430?vs=421667&id=422089#toc

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D123430

Files:
  llvm/test/Transforms/InstCombine/select-binop-cmp.ll


Index: llvm/test/Transforms/InstCombine/select-binop-cmp.ll
===================================================================
--- llvm/test/Transforms/InstCombine/select-binop-cmp.ll
+++ llvm/test/Transforms/InstCombine/select-binop-cmp.ll
@@ -646,6 +646,71 @@
   ret i32 %C
 }
 
+define i32 @select_lshr_icmp_const(i32 %x) {
+; CHECK-LABEL: @select_lshr_icmp_const(
+; CHECK-NEXT:    [[A:%.*]] = icmp ugt i32 %x, 31
+; CHECK-NEXT:    [[B:%.*]] = lshr i32 %x, 5
+; CHECK-NEXT:    [[C:%.*]] = select i1 [[A]], i32 [[B]], i32 0
+; CHECK-NEXT:    ret i32 [[C]]
+;
+  %A = icmp ugt i32 %x, 31
+  %B = lshr i32 %x, 5
+  %C = select i1 %A, i32 %B, i32 0
+  ret i32 %C
+}
+
+define i32 @select_lshr_icmp_const_reordered(i32 %x) {
+; CHECK-LABEL: @select_lshr_icmp_const_reordered(
+; CHECK-NEXT:    [[A:%.*]] = icmp ult i32 %x, 32
+; CHECK-NEXT:    [[B:%.*]] = lshr i32 %x, 5
+; CHECK-NEXT:    [[C:%.*]] = select i1 [[A]], i32 0, i32 [[B]]
+; CHECK-NEXT:    ret i32 [[C]]
+;
+  %A = icmp ult i32 %x, 32
+  %B = lshr i32 %x, 5
+  %C = select i1 %A, i32 0, i32 %B
+  ret i32 %C
+}
+
+define i32 @select_exact_lshr_icmp_const(i32 %x) {
+; CHECK-LABEL: @select_exact_lshr_icmp_const(
+; CHECK-NEXT:    [[A:%.*]] = icmp ugt i32 %x, 31
+; CHECK-NEXT:    [[B:%.*]] = lshr exact i32 %x, 5
+; CHECK-NEXT:    [[C:%.*]] = select i1 [[A]], i32 [[B]], i32 0
+; CHECK-NEXT:    ret i32 [[C]]
+;
+  %A = icmp ugt i32 %x, 31
+  %B = lshr exact i32 %x, 5
+  %C = select i1 %A, i32 %B, i32 0
+  ret i32 %C
+}
+
+define i32 @select_lshr_icmp_const_large_exact_range(i32 %x) {
+; CHECK-LABEL: @select_lshr_icmp_const_large_exact_range(
+; CHECK-NEXT:    [[A:%.*]] = icmp ugt i32 %x, 63
+; CHECK-NEXT:    [[B:%.*]] = lshr i32 %x, 5
+; CHECK-NEXT:    [[C:%.*]] = select i1 [[A]], i32 [[B]], i32 0
+; CHECK-NEXT:    ret i32 [[C]]
+;
+  %A = icmp ugt i32 %x, 63
+  %B = lshr i32 %x, 5
+  %C = select i1 %A, i32 %B, i32 0
+  ret i32 %C
+}
+
+define i32 @select_lshr_icmp_const_different_values(i32 %x, i32 %y) {
+; CHECK-LABEL: @select_lshr_icmp_const_different_values(
+; CHECK-NEXT:    [[A:%.*]] = icmp ugt i32 %x, 31
+; CHECK-NEXT:    [[B:%.*]] = lshr i32 %y, 5
+; CHECK-NEXT:    [[C:%.*]] = select i1 [[A]], i32 [[B]], i32 0
+; CHECK-NEXT:    ret i32 [[C]]
+;
+  %A = icmp ugt i32 %x, 31
+  %B = lshr i32 %y, 5
+  %C = select i1 %A, i32 %B, i32 0
+  ret i32 %C
+}
+
 ; Invalid identity constant for FP op
 define float @select_fadd_fcmp_bad(float %x, float %y, float %z) {
 ; CHECK-LABEL: @select_fadd_fcmp_bad(


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D123430.422089.patch
Type: text/x-patch
Size: 2485 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20220412/be36ec36/attachment.bin>


More information about the llvm-commits mailing list