From 12a499eb00e36bb0944c6b1f7f8721fd90a5bd8f Mon Sep 17 00:00:00 2001 From: Bjorn Pettersson Date: Tue, 18 Jan 2022 19:48:35 +0100 Subject: [PATCH] Pre-commit test case for trunc+lshr+load folds This is a pre-commit of test cases relevant for D117406. @srl_load_narrowing1 is showing a pattern that could be folded into a more narrow load. @srl_load_narrowing2 is showing a similar pattern that happens to be optimized already, but that happens in two steps (first triggering a combine based on SRL and later another combine based on TRUNCATE). Differential Revision: https://reviews.llvm.org/D117588 --- llvm/test/CodeGen/X86/shift-folding.ll | 27 ++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/llvm/test/CodeGen/X86/shift-folding.ll b/llvm/test/CodeGen/X86/shift-folding.ll index 539649b7cd47..cc03b4b9480a 100644 --- a/llvm/test/CodeGen/X86/shift-folding.ll +++ b/llvm/test/CodeGen/X86/shift-folding.ll @@ -83,3 +83,30 @@ define i32 @overshift(i32 %a) { ret i32 %xor } +; Should be possible to adjust the pointer and narrow the load to 16 bits. +define i16 @srl_load_narrowing1(i32* %arg) { +; CHECK-LABEL: srl_load_narrowing1: +; CHECK: # %bb.0: +; CHECK-NEXT: movl {{[0-9]+}}(%esp), %eax +; CHECK-NEXT: movl (%eax), %eax +; CHECK-NEXT: shrl $8, %eax +; CHECK-NEXT: # kill: def $ax killed $ax killed $eax +; CHECK-NEXT: retl + %tmp1 = load i32, i32* %arg, align 1 + %tmp2 = lshr i32 %tmp1, 8 + %tmp3 = trunc i32 %tmp2 to i16 + ret i16 %tmp3 +} + +define i16 @srl_load_narrowing2(i32* %arg) { +; CHECK-LABEL: srl_load_narrowing2: +; CHECK: # %bb.0: +; CHECK-NEXT: movl {{[0-9]+}}(%esp), %eax +; CHECK-NEXT: movzbl 3(%eax), %eax +; CHECK-NEXT: # kill: def $ax killed $ax killed $eax +; CHECK-NEXT: retl + %tmp1 = load i32, i32* %arg, align 1 + %tmp2 = lshr i32 %tmp1, 24 + %tmp3 = trunc i32 %tmp2 to i16 + ret i16 %tmp3 +}