[PATCH] D117588: Pre-commit test case for trunc+lshr+load folds

Bjorn Pettersson via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Tue Jan 18 10:49:45 PST 2022


bjope created this revision.
Herald added a subscriber: pengfei.
bjope requested review of this revision.
Herald added a project: LLVM.

This is a pre-commit of test cases relevant for D117406 <https://reviews.llvm.org/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).


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D117588

Files:
  llvm/test/CodeGen/X86/shift-folding.ll


Index: llvm/test/CodeGen/X86/shift-folding.ll
===================================================================
--- llvm/test/CodeGen/X86/shift-folding.ll
+++ llvm/test/CodeGen/X86/shift-folding.ll
@@ -83,3 +83,30 @@
   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
+}


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D117588.400914.patch
Type: text/x-patch
Size: 1140 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20220118/c967cc91/attachment.bin>


More information about the llvm-commits mailing list