[llvm] e8fdd03 - [InstCombine] add tests for icmp with trunc op; NFC

Sanjay Patel via llvm-commits llvm-commits at lists.llvm.org
Tue Oct 26 14:44:54 PDT 2021


Author: Sanjay Patel
Date: 2021-10-26T17:43:28-04:00
New Revision: e8fdd030b1c3b971286b2353f2514b3cabb3fe5a

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

LOG: [InstCombine] add tests for icmp with trunc op; NFC

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

Modified: 
    

Removed: 
    


################################################################################
diff  --git a/llvm/test/Transforms/InstCombine/icmp-trunc.ll b/llvm/test/Transforms/InstCombine/icmp-trunc.ll
new file mode 100644
index 000000000000..7f961f2ccfaf
--- /dev/null
+++ b/llvm/test/Transforms/InstCombine/icmp-trunc.ll
@@ -0,0 +1,72 @@
+; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
+; RUN: opt < %s -instcombine -S | FileCheck %s
+
+declare void @use(i8)
+
+define i1 @ult_2(i32 %x) {
+; CHECK-LABEL: @ult_2(
+; CHECK-NEXT:    [[T:%.*]] = trunc i32 [[X:%.*]] to i8
+; CHECK-NEXT:    [[R:%.*]] = icmp ult i8 [[T]], 2
+; CHECK-NEXT:    ret i1 [[R]]
+;
+  %t = trunc i32 %x to i8
+  %r = icmp ult i8 %t, 2
+  ret i1 %r
+}
+
+define <2 x i1> @ult_16_splat(<2 x i16> %x) {
+; CHECK-LABEL: @ult_16_splat(
+; CHECK-NEXT:    [[T:%.*]] = trunc <2 x i16> [[X:%.*]] to <2 x i11>
+; CHECK-NEXT:    [[R:%.*]] = icmp ult <2 x i11> [[T]], <i11 16, i11 16>
+; CHECK-NEXT:    ret <2 x i1> [[R]]
+;
+  %t = trunc <2 x i16> %x to <2 x i11>
+  %r = icmp ult <2 x i11> %t, <i11 16, i11 16>
+  ret <2 x i1> %r
+}
+
+define i1 @ult_3(i32 %x) {
+; CHECK-LABEL: @ult_3(
+; CHECK-NEXT:    [[T:%.*]] = trunc i32 [[X:%.*]] to i8
+; CHECK-NEXT:    [[R:%.*]] = icmp ult i8 [[T]], 3
+; CHECK-NEXT:    ret i1 [[R]]
+;
+  %t = trunc i32 %x to i8
+  %r = icmp ult i8 %t, 3
+  ret i1 %r
+}
+
+define i1 @ult_2_use(i32 %x) {
+; CHECK-LABEL: @ult_2_use(
+; CHECK-NEXT:    [[T:%.*]] = trunc i32 [[X:%.*]] to i8
+; CHECK-NEXT:    call void @use(i8 [[T]])
+; CHECK-NEXT:    [[R:%.*]] = icmp ult i8 [[T]], 2
+; CHECK-NEXT:    ret i1 [[R]]
+;
+  %t = trunc i32 %x to i8
+  call void @use(i8 %t)
+  %r = icmp ult i8 %t, 2
+  ret i1 %r
+}
+
+ at a = internal unnamed_addr constant [3 x i32] [i32 0, i32 0, i32 1], align 4
+
+define i1 @PR52260(i32 %x) {
+; CHECK-LABEL: @PR52260(
+; CHECK-NEXT:    [[IDXPROM:%.*]] = sext i32 [[X:%.*]] to i64
+; CHECK-NEXT:    [[IDX:%.*]] = getelementptr inbounds [3 x i32], [3 x i32]* @a, i64 0, i64 [[IDXPROM]]
+; CHECK-NEXT:    [[T1:%.*]] = load i32, i32* [[IDX]], align 4
+; CHECK-NEXT:    [[TMP1:%.*]] = trunc i32 [[T1]] to i8
+; CHECK-NEXT:    [[TOBOOL:%.*]] = icmp ult i8 [[TMP1]], 2
+; CHECK-NEXT:    ret i1 [[TOBOOL]]
+;
+  %idxprom = sext i32 %x to i64
+  %idx = getelementptr inbounds [3 x i32], [3 x i32]* @a, i64 0, i64 %idxprom
+  %t1 = load i32, i32* %idx, align 4
+  %conv1 = lshr i32 %t1, 1
+  %t2 = trunc i32 %conv1 to i8
+  %conv2 = and i8 %t2, 127
+  %tobool = icmp eq i8 %conv2, 0
+  ret i1 %tobool
+}
+


        


More information about the llvm-commits mailing list