[InstCombine] add test for possible cast-of-select transform; NFC
authorSanjay Patel <spatel@rotateright.com>
Tue, 14 Jan 2020 18:51:22 +0000 (13:51 -0500)
committerSanjay Patel <spatel@rotateright.com>
Tue, 14 Jan 2020 19:23:14 +0000 (14:23 -0500)
llvm/test/Transforms/InstCombine/trunc.ll

index 750f624..146d0ff 100644 (file)
@@ -626,3 +626,21 @@ define <2 x i8> @narrow_sub_vec_constant(<2 x i32> %x) {
   ret <2 x i8> %tr
 }
 
+; FIXME: If the select is narrowed based on the target's datalayout, we allow more optimizations.
+
+define i16 @PR44545(i32 %t0, i32 %data) {
+; CHECK-LABEL: @PR44545(
+; CHECK-NEXT:    [[T1:%.*]] = add nuw nsw i32 [[T0:%.*]], 1
+; CHECK-NEXT:    [[ISZERO:%.*]] = icmp eq i32 [[DATA:%.*]], 0
+; CHECK-NEXT:    [[FFS:%.*]] = select i1 [[ISZERO]], i32 0, i32 [[T1]]
+; CHECK-NEXT:    [[CAST:%.*]] = trunc i32 [[FFS]] to i16
+; CHECK-NEXT:    [[SUB:%.*]] = add nsw i16 [[CAST]], -1
+; CHECK-NEXT:    ret i16 [[SUB]]
+;
+  %t1 = add nuw nsw i32 %t0, 1
+  %iszero = icmp eq i32 %data, 0
+  %ffs = select i1 %iszero, i32 0, i32 %t1
+  %cast = trunc i32 %ffs to i16
+  %sub = add nsw i16 %cast, -1
+  ret i16 %sub
+}