[llvm] r357050 - [X86] Add test cases for missed opportunities in (x << C1) op C2 to (x op (C2>>C1)) << C1 transform.

Craig Topper via llvm-commits llvm-commits at lists.llvm.org
Tue Mar 26 23:07:05 PDT 2019


Author: ctopper
Date: Tue Mar 26 23:07:05 2019
New Revision: 357050

URL: http://llvm.org/viewvc/llvm-project?rev=357050&view=rev
Log:
[X86] Add test cases for missed opportunities in (x << C1) op C2 to (x op (C2>>C1)) << C1 transform.

We handle the case where the C2 does not fit in a signed 32-bit immediate, but
(C2>>C1) does. But there's also some 64-bit opportunities when C2 is not an unsigned
32-bit immediate, but (C2>>C1) is. For OR/XOR this allows us to load the
immediate with with MOV32ri instead of a movabsq. For AND it allows us to use a
32-bit AND and fold the immediate.

Modified:
    llvm/trunk/test/CodeGen/X86/narrow-shl-cst.ll

Modified: llvm/trunk/test/CodeGen/X86/narrow-shl-cst.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/CodeGen/X86/narrow-shl-cst.ll?rev=357050&r1=357049&r2=357050&view=diff
==============================================================================
--- llvm/trunk/test/CodeGen/X86/narrow-shl-cst.ll (original)
+++ llvm/trunk/test/CodeGen/X86/narrow-shl-cst.ll Tue Mar 26 23:07:05 2019
@@ -162,3 +162,39 @@ define i64 @test13(i64 %x, i64* %y) noun
   store i64 %shl, i64* %y
   ret i64 %shl
 }
+
+define i64 @test14(i64 %x, i64* %y) nounwind {
+; CHECK-LABEL: test14:
+; CHECK:       # %bb.0:
+; CHECK-NEXT:    shlq $8, %rdi
+; CHECK-NEXT:    movabsq $1095216660480, %rax # imm = 0xFF00000000
+; CHECK-NEXT:    andq %rdi, %rax
+; CHECK-NEXT:    retq
+  %and = shl i64 %x, 8
+  %shl = and i64 %and, 1095216660480
+  ret i64 %shl
+}
+
+define i64 @test15(i64 %x, i64* %y) nounwind {
+; CHECK-LABEL: test15:
+; CHECK:       # %bb.0:
+; CHECK-NEXT:    shlq $8, %rdi
+; CHECK-NEXT:    movabsq $1095216660480, %rax # imm = 0xFF00000000
+; CHECK-NEXT:    orq %rdi, %rax
+; CHECK-NEXT:    retq
+  %or = shl i64 %x, 8
+  %shl = or i64 %or, 1095216660480
+  ret i64 %shl
+}
+
+define i64 @test16(i64 %x, i64* %y) nounwind {
+; CHECK-LABEL: test16:
+; CHECK:       # %bb.0:
+; CHECK-NEXT:    shlq $8, %rdi
+; CHECK-NEXT:    movabsq $1095216660480, %rax # imm = 0xFF00000000
+; CHECK-NEXT:    xorq %rdi, %rax
+; CHECK-NEXT:    retq
+  %xor = shl i64 %x, 8
+  %shl = xor i64 %xor, 1095216660480
+  ret i64 %shl
+}




More information about the llvm-commits mailing list