[InstCombine] add tests to show missing one-use checks; NFC
authorSanjay Patel <spatel@rotateright.com>
Fri, 3 Jul 2020 15:28:03 +0000 (11:28 -0400)
committerSanjay Patel <spatel@rotateright.com>
Fri, 3 Jul 2020 15:54:09 +0000 (11:54 -0400)
llvm/test/Transforms/InstCombine/select-bitext.ll

index d44be27..d39dca9 100644 (file)
@@ -1,6 +1,8 @@
 ; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
 ; RUN: opt < %s -instcombine -S | FileCheck %s
 
+declare void @use32(i32)
+
 ; Widen a select of constants to eliminate an extend.
 
 define i16 @sel_sext_constants(i1 %cmp) {
@@ -451,6 +453,38 @@ define i32 @test_bits_zext(i8 %a, i1 %cc) {
   ret i32 %r
 }
 
+define i32 @sel_sext_const_uses(i8 %a, i8 %x) {
+; CHECK-LABEL: @sel_sext_const_uses(
+; CHECK-NEXT:    [[COND:%.*]] = icmp ugt i8 [[X:%.*]], 15
+; CHECK-NEXT:    [[A_EXT:%.*]] = sext i8 [[A:%.*]] to i32
+; CHECK-NEXT:    call void @use32(i32 [[A_EXT]])
+; CHECK-NEXT:    [[NARROW:%.*]] = select i1 [[COND]], i8 [[A]], i8 127
+; CHECK-NEXT:    [[R:%.*]] = sext i8 [[NARROW]] to i32
+; CHECK-NEXT:    ret i32 [[R]]
+;
+  %cond = icmp ugt i8 %x, 15
+  %a.ext = sext i8 %a to i32
+  call void @use32(i32 %a.ext)
+  %r = select i1 %cond, i32 %a.ext, i32 127
+  ret i32 %r
+}
+
+define i32 @sel_zext_const_uses(i8 %a, i8 %x) {
+; CHECK-LABEL: @sel_zext_const_uses(
+; CHECK-NEXT:    [[COND:%.*]] = icmp sgt i8 [[X:%.*]], 15
+; CHECK-NEXT:    [[A_EXT:%.*]] = zext i8 [[A:%.*]] to i32
+; CHECK-NEXT:    call void @use32(i32 [[A_EXT]])
+; CHECK-NEXT:    [[NARROW:%.*]] = select i1 [[COND]], i8 -1, i8 [[A]]
+; CHECK-NEXT:    [[R:%.*]] = zext i8 [[NARROW]] to i32
+; CHECK-NEXT:    ret i32 [[R]]
+;
+  %cond = icmp sgt i8 %x, 15
+  %a.ext = zext i8 %a to i32
+  call void @use32(i32 %a.ext)
+  %r = select i1 %cond, i32 255, i32 %a.ext
+  ret i32 %r
+}
+
 define i32 @test_op_op(i32 %a, i32 %b, i32 %c) {
 ; CHECK-LABEL: @test_op_op(
 ; CHECK-NEXT:    [[CCA:%.*]] = icmp sgt i32 [[A:%.*]], 0