[llvm] [PowerPC] Optimize BUILD_VECTOR from load and zeros (PR #73609)
Kai Luo via llvm-commits
llvm-commits at lists.llvm.org
Tue Dec 5 21:26:28 PST 2023
================
@@ -3542,6 +3630,54 @@ foreach Idx = [ [0,2], [1,1], [3,3] ] in {
(STIWX (EXTRACT_SUBREG (XXSLDWI $A, $A, !head(!tail(Idx))),
sub_64), ForceXForm:$src)>;
}
+
+// BUILD_VECTOR via single load and zeros.
+// Extension load.
+def : Pat<(v2f64 BVExtLoadAndZerosFP<1>.DAG),
+ (v2f64 (COPY_TO_REGCLASS (LXSSPX ForceXForm:$src), VSRC))>;
+def : Pat<(v2f64 BVExtLoadAndZerosFP<0>.DAG),
+ (v2f64 (XXPERMDIs
+ (COPY_TO_REGCLASS (LXSSPX ForceXForm:$src), VSRC), 2))>;
+
+def : Pat<(v2i64 BVZExtLoadAndZerosInt<1>.DAG),
+ (v2i64 (COPY_TO_REGCLASS (LXSIWZX ForceXForm:$src), VSRC))>;
+def : Pat<(v2i64 BVZExtLoadAndZerosInt<0>.DAG),
+ (v2i64 (XXPERMDIs
+ (COPY_TO_REGCLASS (LXSIWZX ForceXForm:$src), VSRC), 2))>;
+
+// Normal load.
+foreach Index = !range(4) in {
+ defvar Temp = !sub(!add(Index, 4), 2);
+ defvar Offset = !if(!gt(Temp, 3), !sub(Temp, 4), Temp);
+ if !ne(Offset, 0) then {
+ def : Pat<(v4i32 BVLoadAndZerosInt<Index>.DAG),
+ (v4i32 (XXSLDWIs
+ (COPY_TO_REGCLASS (LXSIWZX ForceXForm:$src), VSRC),
+ Offset))>;
+ def : Pat<(v4f32 BVLoadAndZerosFP<Index>.DAG),
+ (v4f32 (XXSLDWIs
+ (COPY_TO_REGCLASS (LXSIWZX ForceXForm:$src), VSRC),
+ Offset))>;
+ } else {
+ def : Pat<(v4i32 BVLoadAndZerosInt<Index>.DAG),
+ (v4i32 (COPY_TO_REGCLASS (LXSIWZX ForceXForm:$src), VSRC))>;
+ def : Pat<(v4f32 BVLoadAndZerosFP<Index>.DAG),
+ (v4f32 (COPY_TO_REGCLASS (LXSIWZX ForceXForm:$src), VSRC))>;
+ }
+}
+
+def : Pat<(v2f64 BVLoadAndZerosDbl<1>.DAG),
+ (v2f64 (COPY_TO_REGCLASS (LXSDX ForceXForm:$src), VSRC))>;
+def : Pat<(v2f64 BVLoadAndZerosDbl<0>.DAG),
+ (v2f64 (XXPERMDIs
+ (COPY_TO_REGCLASS (LXSDX ForceXForm:$src), VSRC), 2))>;
+
+def : Pat<(v2i64 BVLoadAndZerosLong<1>.DAG),
+ (v2i64 (COPY_TO_REGCLASS (LXSDX ForceXForm:$src), VSRC))>;
+def : Pat<(v2i64 BVLoadAndZerosLong<0>.DAG),
+ (v2i64 (XXPERMDIs
+ (COPY_TO_REGCLASS (LXSDX ForceXForm:$src), VSRC), 2))>;
----------------
bzEq wrote:
I've tried, however looks not simplified much(Maybe I was using a different approach than what's in your mind).
https://github.com/llvm/llvm-project/pull/73609
More information about the llvm-commits
mailing list