[llvm] r236973 - [InstCombine/PowerPC] Fix single-precision QPX load/store replacement

Hal Finkel hfinkel at anl.gov
Sun May 10 23:37:03 PDT 2015


Author: hfinkel
Date: Mon May 11 01:37:03 2015
New Revision: 236973

URL: http://llvm.org/viewvc/llvm-project?rev=236973&view=rev
Log:
[InstCombine/PowerPC] Fix single-precision QPX load/store replacement

The QPX single-precision load/store intrinsics have implied
truncation/extension from/to the declared value type of <4 x double> to the
memory type of <4 x float>. When we can prove the alignment of the pointer
argument, and thus replace the intrinsic with a regular load or store, we need
to load or store the correct data type (<4 x float>) instead of (<4 x double>).

Modified:
    llvm/trunk/lib/Transforms/InstCombine/InstCombineCalls.cpp
    llvm/trunk/test/Transforms/InstCombine/aligned-qpx.ll

Modified: llvm/trunk/lib/Transforms/InstCombine/InstCombineCalls.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Transforms/InstCombine/InstCombineCalls.cpp?rev=236973&r1=236972&r2=236973&view=diff
==============================================================================
--- llvm/trunk/lib/Transforms/InstCombine/InstCombineCalls.cpp (original)
+++ llvm/trunk/lib/Transforms/InstCombine/InstCombineCalls.cpp Mon May 11 01:37:03 2015
@@ -624,9 +624,12 @@ Instruction *InstCombiner::visitCallInst
     // Turn PPC QPX qvlfs -> load if the pointer is known aligned.
     if (getOrEnforceKnownAlignment(II->getArgOperand(0), 16, DL, II, AC, DT) >=
         16) {
+      Type *VTy = VectorType::get(Builder->getFloatTy(),
+                                  II->getType()->getVectorNumElements());
       Value *Ptr = Builder->CreateBitCast(II->getArgOperand(0),
-                                         PointerType::getUnqual(II->getType()));
-      return new LoadInst(Ptr);
+                                         PointerType::getUnqual(VTy));
+      Value *Load = Builder->CreateLoad(Ptr);
+      return new FPExtInst(Load, II->getType());
     }
     break;
   case Intrinsic::ppc_qpx_qvlfd:
@@ -642,10 +645,12 @@ Instruction *InstCombiner::visitCallInst
     // Turn PPC QPX qvstfs -> store if the pointer is known aligned.
     if (getOrEnforceKnownAlignment(II->getArgOperand(1), 16, DL, II, AC, DT) >=
         16) {
-      Type *OpPtrTy =
-        PointerType::getUnqual(II->getArgOperand(0)->getType());
+      Type *VTy = VectorType::get(Builder->getFloatTy(),
+          II->getArgOperand(0)->getType()->getVectorNumElements());
+      Value *TOp = Builder->CreateFPTrunc(II->getArgOperand(0), VTy);
+      Type *OpPtrTy = PointerType::getUnqual(VTy);
       Value *Ptr = Builder->CreateBitCast(II->getArgOperand(1), OpPtrTy);
-      return new StoreInst(II->getArgOperand(0), Ptr);
+      return new StoreInst(TOp, Ptr);
     }
     break;
   case Intrinsic::ppc_qpx_qvstfd:

Modified: llvm/trunk/test/Transforms/InstCombine/aligned-qpx.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Transforms/InstCombine/aligned-qpx.ll?rev=236973&r1=236972&r2=236973&view=diff
==============================================================================
--- llvm/trunk/test/Transforms/InstCombine/aligned-qpx.ll (original)
+++ llvm/trunk/test/Transforms/InstCombine/aligned-qpx.ll Mon May 11 01:37:03 2015
@@ -28,6 +28,7 @@ entry:
 
 ; CHECK-LABEL: @test1a
 ; CHECK-NOT: @llvm.ppc.qpx.qvlfs
+; CHECK-NOT: load <4 x double>
 ; CHECK: ret <4 x double>
 
   %v0 = load <4 x float>, <4 x float>* %h, align 8
@@ -62,7 +63,9 @@ entry:
   ret <4 x float> %v0
 
 ; CHECK-LABEL: @test2
+; CHECK: fptrunc <4 x double> %d to <4 x float>
 ; CHECK-NOT: @llvm.ppc.qpx.qvstfs
+; CHECK-NOT: store <4 x double>
 ; CHECK: ret <4 x float>
 }
 





More information about the llvm-commits mailing list