[llvm] d7b6fd4 - [InstCombine] Add additional icmp of select tests (NFC)

Nikita Popov via llvm-commits llvm-commits at lists.llvm.org
Fri May 6 07:04:47 PDT 2022


Author: Nikita Popov
Date: 2022-05-06T16:04:39+02:00
New Revision: d7b6fd47b223c3b5243973188a8598b1eecb1046

URL: https://github.com/llvm/llvm-project/commit/d7b6fd47b223c3b5243973188a8598b1eecb1046
DIFF: https://github.com/llvm/llvm-project/commit/d7b6fd47b223c3b5243973188a8598b1eecb1046.diff

LOG: [InstCombine] Add additional icmp of select tests (NFC)

Added: 
    llvm/test/Transforms/InstCombine/icmp-select.ll

Modified: 
    

Removed: 
    


################################################################################
diff  --git a/llvm/test/Transforms/InstCombine/icmp-select.ll b/llvm/test/Transforms/InstCombine/icmp-select.ll
new file mode 100644
index 0000000000000..36d364563af32
--- /dev/null
+++ b/llvm/test/Transforms/InstCombine/icmp-select.ll
@@ -0,0 +1,161 @@
+; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
+; RUN: opt -S -instcombine < %s | FileCheck %s
+
+declare void @use(i8)
+
+define i1 @icmp_select_const(i8 %x, i8 %y) {
+; CHECK-LABEL: @icmp_select_const(
+; CHECK-NEXT:    [[CMP1:%.*]] = icmp eq i8 [[X:%.*]], 0
+; CHECK-NEXT:    [[CMP21:%.*]] = icmp eq i8 [[Y:%.*]], 0
+; CHECK-NEXT:    [[CMP2:%.*]] = select i1 [[CMP1]], i1 true, i1 [[CMP21]]
+; CHECK-NEXT:    ret i1 [[CMP2]]
+;
+  %cmp1 = icmp eq i8 %x, 0
+  %sel = select i1 %cmp1, i8 0, i8 %y
+  %cmp2 = icmp eq i8 %sel, 0
+  ret i1 %cmp2
+}
+
+define i1 @icmp_select_var(i8 %x, i8 %y, i8 %z) {
+; CHECK-LABEL: @icmp_select_var(
+; CHECK-NEXT:    [[CMP1:%.*]] = icmp eq i8 [[X:%.*]], 0
+; CHECK-NEXT:    [[SEL:%.*]] = select i1 [[CMP1]], i8 [[Z:%.*]], i8 [[Y:%.*]]
+; CHECK-NEXT:    [[CMP2:%.*]] = icmp eq i8 [[SEL]], [[Z]]
+; CHECK-NEXT:    ret i1 [[CMP2]]
+;
+  %cmp1 = icmp eq i8 %x, 0
+  %sel = select i1 %cmp1, i8 %z, i8 %y
+  %cmp2 = icmp eq i8 %sel, %z
+  ret i1 %cmp2
+}
+
+define i1 @icmp_select_var_commuted(i8 %x, i8 %y, i8 %_z) {
+; CHECK-LABEL: @icmp_select_var_commuted(
+; CHECK-NEXT:    [[Z:%.*]] = udiv i8 42, [[_Z:%.*]]
+; CHECK-NEXT:    [[CMP1:%.*]] = icmp eq i8 [[X:%.*]], 0
+; CHECK-NEXT:    [[SEL:%.*]] = select i1 [[CMP1]], i8 [[Z]], i8 [[Y:%.*]]
+; CHECK-NEXT:    [[CMP2:%.*]] = icmp eq i8 [[Z]], [[SEL]]
+; CHECK-NEXT:    ret i1 [[CMP2]]
+;
+  %z = udiv i8 42, %_z ; thwart complexity-based canonicalization
+  %cmp1 = icmp eq i8 %x, 0
+  %sel = select i1 %cmp1, i8 %z, i8 %y
+  %cmp2 = icmp eq i8 %z, %sel
+  ret i1 %cmp2
+}
+
+define i1 @icmp_select_var_select(i8 %x, i8 %y, i1 %c) {
+; CHECK-LABEL: @icmp_select_var_select(
+; CHECK-NEXT:    [[Z:%.*]] = select i1 [[C:%.*]], i8 [[X:%.*]], i8 [[Y:%.*]]
+; CHECK-NEXT:    [[CMP1:%.*]] = icmp eq i8 [[X]], 0
+; CHECK-NEXT:    [[SEL:%.*]] = select i1 [[CMP1]], i8 [[Z]], i8 [[Y]]
+; CHECK-NEXT:    [[CMP2:%.*]] = icmp eq i8 [[Z]], [[SEL]]
+; CHECK-NEXT:    ret i1 [[CMP2]]
+;
+  %z = select i1 %c, i8 %x, i8 %y
+  %cmp1 = icmp eq i8 %x, 0
+  %sel = select i1 %cmp1, i8 %z, i8 %y
+  %cmp2 = icmp eq i8 %z, %sel
+  ret i1 %cmp2
+}
+
+define i1 @icmp_select_var_both_fold(i8 %x, i8 %y, i8 %_z) {
+; CHECK-LABEL: @icmp_select_var_both_fold(
+; CHECK-NEXT:    [[CMP1:%.*]] = icmp eq i8 [[X:%.*]], 0
+; CHECK-NEXT:    ret i1 [[CMP1]]
+;
+  %z = or i8 %_z, 1
+  %cmp1 = icmp eq i8 %x, 0
+  %sel = select i1 %cmp1, i8 %z, i8 2
+  %cmp2 = icmp eq i8 %sel, %z
+  ret i1 %cmp2
+}
+
+define i1 @icmp_select_var_extra_use(i8 %x, i8 %y, i8 %z) {
+; CHECK-LABEL: @icmp_select_var_extra_use(
+; CHECK-NEXT:    [[CMP1:%.*]] = icmp eq i8 [[X:%.*]], 0
+; CHECK-NEXT:    [[SEL:%.*]] = select i1 [[CMP1]], i8 [[Z:%.*]], i8 [[Y:%.*]]
+; CHECK-NEXT:    call void @use(i8 [[SEL]])
+; CHECK-NEXT:    [[CMP2:%.*]] = icmp eq i8 [[SEL]], [[Z]]
+; CHECK-NEXT:    ret i1 [[CMP2]]
+;
+  %cmp1 = icmp eq i8 %x, 0
+  %sel = select i1 %cmp1, i8 %z, i8 %y
+  call void @use(i8 %sel)
+  %cmp2 = icmp eq i8 %sel, %z
+  ret i1 %cmp2
+}
+
+define i1 @icmp_select_var_both_fold_extra_use(i8 %x, i8 %y, i8 %_z) {
+; CHECK-LABEL: @icmp_select_var_both_fold_extra_use(
+; CHECK-NEXT:    [[Z:%.*]] = or i8 [[_Z:%.*]], 1
+; CHECK-NEXT:    [[CMP1:%.*]] = icmp eq i8 [[X:%.*]], 0
+; CHECK-NEXT:    [[SEL:%.*]] = select i1 [[CMP1]], i8 [[Z]], i8 2
+; CHECK-NEXT:    call void @use(i8 [[SEL]])
+; CHECK-NEXT:    ret i1 [[CMP1]]
+;
+  %z = or i8 %_z, 1
+  %cmp1 = icmp eq i8 %x, 0
+  %sel = select i1 %cmp1, i8 %z, i8 2
+  call void @use(i8 %sel)
+  %cmp2 = icmp eq i8 %sel, %z
+  ret i1 %cmp2
+}
+
+define i1 @icmp_select_var_pred_ne(i8 %x, i8 %y, i8 %z) {
+; CHECK-LABEL: @icmp_select_var_pred_ne(
+; CHECK-NEXT:    [[CMP1:%.*]] = icmp eq i8 [[X:%.*]], 0
+; CHECK-NEXT:    [[SEL:%.*]] = select i1 [[CMP1]], i8 [[Z:%.*]], i8 [[Y:%.*]]
+; CHECK-NEXT:    [[CMP2:%.*]] = icmp ne i8 [[SEL]], [[Z]]
+; CHECK-NEXT:    ret i1 [[CMP2]]
+;
+  %cmp1 = icmp eq i8 %x, 0
+  %sel = select i1 %cmp1, i8 %z, i8 %y
+  %cmp2 = icmp ne i8 %sel, %z
+  ret i1 %cmp2
+}
+
+define i1 @icmp_select_var_pred_ult(i8 %x, i8 %y, i8 %z) {
+; CHECK-LABEL: @icmp_select_var_pred_ult(
+; CHECK-NEXT:    [[Z1:%.*]] = add nuw i8 [[Z:%.*]], 2
+; CHECK-NEXT:    [[CMP1:%.*]] = icmp eq i8 [[X:%.*]], 0
+; CHECK-NEXT:    [[SEL:%.*]] = select i1 [[CMP1]], i8 [[Z]], i8 [[Y:%.*]]
+; CHECK-NEXT:    [[CMP2:%.*]] = icmp ult i8 [[SEL]], [[Z1]]
+; CHECK-NEXT:    ret i1 [[CMP2]]
+;
+  %z1 = add nuw i8 %z, 2
+  %cmp1 = icmp eq i8 %x, 0
+  %sel = select i1 %cmp1, i8 %z, i8 %y
+  %cmp2 = icmp ult i8 %sel, %z1
+  ret i1 %cmp2
+}
+
+define i1 @icmp_select_var_pred_uge(i8 %x, i8 %y, i8 %z) {
+; CHECK-LABEL: @icmp_select_var_pred_uge(
+; CHECK-NEXT:    [[Z1:%.*]] = add nuw i8 [[Z:%.*]], 2
+; CHECK-NEXT:    [[CMP1:%.*]] = icmp eq i8 [[X:%.*]], 0
+; CHECK-NEXT:    [[SEL:%.*]] = select i1 [[CMP1]], i8 [[Z]], i8 [[Y:%.*]]
+; CHECK-NEXT:    [[CMP2:%.*]] = icmp uge i8 [[SEL]], [[Z1]]
+; CHECK-NEXT:    ret i1 [[CMP2]]
+;
+  %z1 = add nuw i8 %z, 2
+  %cmp1 = icmp eq i8 %x, 0
+  %sel = select i1 %cmp1, i8 %z, i8 %y
+  %cmp2 = icmp uge i8 %sel, %z1
+  ret i1 %cmp2
+}
+
+define i1 @icmp_select_var_pred_uge_commuted(i8 %x, i8 %y, i8 %z) {
+; CHECK-LABEL: @icmp_select_var_pred_uge_commuted(
+; CHECK-NEXT:    [[Z1:%.*]] = add nuw i8 [[Z:%.*]], 2
+; CHECK-NEXT:    [[CMP1:%.*]] = icmp eq i8 [[X:%.*]], 0
+; CHECK-NEXT:    [[SEL:%.*]] = select i1 [[CMP1]], i8 [[Z]], i8 [[Y:%.*]]
+; CHECK-NEXT:    [[CMP2:%.*]] = icmp uge i8 [[Z1]], [[SEL]]
+; CHECK-NEXT:    ret i1 [[CMP2]]
+;
+  %z1 = add nuw i8 %z, 2
+  %cmp1 = icmp eq i8 %x, 0
+  %sel = select i1 %cmp1, i8 %z, i8 %y
+  %cmp2 = icmp uge i8 %z1, %sel
+  ret i1 %cmp2
+}


        


More information about the llvm-commits mailing list