[PATCH] D107428: [PowerPC] Fix shift amount of xxsldwi when performing vector int_to_double

Kai Luo via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Wed Aug 4 00:33:03 PDT 2021


lkail created this revision.
lkail added reviewers: nemanjai, shchenz, qiucf, PowerPC.
Herald added subscribers: kbarton, hiraditya.
lkail requested review of this revision.
Herald added a project: LLVM.
Herald added a subscriber: llvm-commits.

POC

  // main.c
  #include <stdio.h>
  #include <altivec.h>
  extern vector double foo(vector int s);
  int main() {
    vector int s = {0, 1, 0, 4};
    vector double vd;
    vd = foo(s);
    printf("%lf %lf\n", vd[0], vd[1]);
    return 0;
  }
  // poc.c
  #include <stdio.h>
  #include <altivec.h>
  extern vector double foo(vector int s);
  int main() {
    vector int s = {0, 1, 0, 4};
    vector double vd;
    vd = foo(s);
    printf("%lf %lf\n", vd[0], vd[1]);
    return 0;
  }

Current clang gives

  4.000000 1.000000

while xlc gives

  1.000000 4.000000

Xlc's output should be correct.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D107428

Files:
  llvm/lib/Target/PowerPC/PPCInstrVSX.td
  llvm/test/CodeGen/PowerPC/build-vector-tests.ll


Index: llvm/test/CodeGen/PowerPC/build-vector-tests.ll
===================================================================
--- llvm/test/CodeGen/PowerPC/build-vector-tests.ll
+++ llvm/test/CodeGen/PowerPC/build-vector-tests.ll
@@ -6160,7 +6160,7 @@
 define dso_local <2 x double> @sint_to_fp_widen13(<4 x i32> %a) {
 ; P9BE-LABEL: sint_to_fp_widen13:
 ; P9BE:       # %bb.0: # %entry
-; P9BE-NEXT:    xxsldwi vs0, v2, v2, 3
+; P9BE-NEXT:    xxsldwi vs0, v2, v2, 1
 ; P9BE-NEXT:    xvcvsxwdp v2, vs0
 ; P9BE-NEXT:    blr
 ;
@@ -6171,7 +6171,7 @@
 ;
 ; P8BE-LABEL: sint_to_fp_widen13:
 ; P8BE:       # %bb.0: # %entry
-; P8BE-NEXT:    xxsldwi vs0, v2, v2, 3
+; P8BE-NEXT:    xxsldwi vs0, v2, v2, 1
 ; P8BE-NEXT:    xvcvsxwdp v2, vs0
 ; P8BE-NEXT:    blr
 ;
Index: llvm/lib/Target/PowerPC/PPCInstrVSX.td
===================================================================
--- llvm/lib/Target/PowerPC/PPCInstrVSX.td
+++ llvm/lib/Target/PowerPC/PPCInstrVSX.td
@@ -2962,7 +2962,7 @@
 def : Pat<WToDPExtractConv.BV02S,
           (v2f64 (XVCVSXWDP $A))>;
 def : Pat<WToDPExtractConv.BV13S,
-          (v2f64 (XVCVSXWDP (XXSLDWI $A, $A, 3)))>;
+          (v2f64 (XVCVSXWDP (XXSLDWI $A, $A, 1)))>;
 def : Pat<WToDPExtractConv.BV02U,
           (v2f64 (XVCVUXWDP $A))>;
 def : Pat<WToDPExtractConv.BV13U,


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D107428.363985.patch
Type: text/x-patch
Size: 1295 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20210804/a07d3165/attachment.bin>


More information about the llvm-commits mailing list