From 17d508f30d897e7392e48885850c9595546e342c Mon Sep 17 00:00:00 2001 From: Andreas Jonson Date: Sun, 16 Feb 2025 15:27:38 +0100 Subject: [PATCH] [InstCombine] Test foldSelectICmpAnd with cast. (NFC) --- .../Transforms/InstCombine/select-icmp-and.ll | 46 +++++++++++++++++++ 1 file changed, 46 insertions(+) diff --git a/llvm/test/Transforms/InstCombine/select-icmp-and.ll b/llvm/test/Transforms/InstCombine/select-icmp-and.ll index 7c95fc125ce7..516a1e8496b4 100644 --- a/llvm/test/Transforms/InstCombine/select-icmp-and.ll +++ b/llvm/test/Transforms/InstCombine/select-icmp-and.ll @@ -388,6 +388,37 @@ define i32 @test15e_extra_use(i32 %X) { ret i32 %t3 } +;; (a & 128) ? 256 : 0 +define i32 @test15e_zext(i8 %X) { +; CHECK-LABEL: @test15e_zext( +; CHECK-NEXT: [[TMP1:%.*]] = and i8 [[X:%.*]], -128 +; CHECK-NEXT: [[TMP2:%.*]] = zext i8 [[TMP1]] to i32 +; CHECK-NEXT: [[T3:%.*]] = shl nuw nsw i32 [[TMP2]], 1 +; CHECK-NEXT: ret i32 [[T3]] +; + %t1 = and i8 %X, 128 + %t2 = icmp ne i8 %t1, 0 + %t3 = select i1 %t2, i32 256, i32 0 + ret i32 %t3 +} + +;; (a & 128) ? 256 : 0 +define i32 @test15e_zext_extra_use(i8 %X) { +; CHECK-LABEL: @test15e_zext_extra_use( +; CHECK-NEXT: [[T2:%.*]] = icmp slt i8 [[X:%.*]], 0 +; CHECK-NEXT: [[TMP1:%.*]] = and i8 [[X]], -128 +; CHECK-NEXT: [[TMP2:%.*]] = zext i8 [[TMP1]] to i32 +; CHECK-NEXT: [[T3:%.*]] = shl nuw nsw i32 [[TMP2]], 1 +; CHECK-NEXT: call void @use1(i1 [[T2]]) +; CHECK-NEXT: ret i32 [[T3]] +; + %t1 = and i8 %X, 128 + %t2 = icmp ne i8 %t1, 0 + %t3 = select i1 %t2, i32 256, i32 0 + call void @use1(i1 %t2) + ret i32 %t3 +} + ;; (a & 128) ? 0 : 256 define i32 @test15f(i32 %X) { ; CHECK-LABEL: @test15f( @@ -419,6 +450,21 @@ define i32 @test15f_extra_use(i32 %X) { ret i32 %t3 } +;; (a & 128) ? 0 : 256 +define i16 @test15f_trunc(i32 %X) { +; CHECK-LABEL: @test15f_trunc( +; CHECK-NEXT: [[TMP1:%.*]] = trunc i32 [[X:%.*]] to i16 +; CHECK-NEXT: [[TMP2:%.*]] = shl i16 [[TMP1]], 1 +; CHECK-NEXT: [[TMP3:%.*]] = and i16 [[TMP2]], 256 +; CHECK-NEXT: [[T3:%.*]] = xor i16 [[TMP3]], 256 +; CHECK-NEXT: ret i16 [[T3]] +; + %t1 = and i32 %X, 128 + %t2 = icmp ne i32 %t1, 0 + %t3 = select i1 %t2, i16 0, i16 256 + ret i16 %t3 +} + ;; (a & 8) ? -1 : -9 define i32 @test15g(i32 %X) { ; CHECK-LABEL: @test15g(