[llvm] r182012 - [PowerPC] Report true displacement value from getPreIndexedAddressParts

Ulrich Weigand ulrich.weigand at de.ibm.com
Thu May 16 07:53:05 PDT 2013


Author: uweigand
Date: Thu May 16 09:53:05 2013
New Revision: 182012

URL: http://llvm.org/viewvc/llvm-project?rev=182012&view=rev
Log:

[PowerPC] Report true displacement value from getPreIndexedAddressParts

DAGCombiner::CombineToPreIndexedLoadStore calls a target routine to
decompose a memory address into a base/offset pair.  It expects the
offset (if constant) to be the true displacement value in order to
perform optional additional optimizations; in particular, to convert
other uses of the original pointer into uses of the new base pointer
after pre-increment.

The PowerPC implementation of getPreIndexedAddressParts, however,
simply calls SelectAddressRegImm, which returns a TargetConstant.
This value is appropriate for encoding into the instruction, but
it is not always usable as true displacement value:

- Its type is always MVT::i32, even on 64-bit, where addresses
  ought to be i64 ... this causes the optimization to simply
  always fail on 64-bit due to this line in DAGCombiner:

      // FIXME: In some cases, we can be smarter about this.
      if (Op1.getValueType() != Offset.getValueType()) {

- Its value is truncated to an unsigned 16-bit value if negative.
  This causes the above opimization to generate wrong code.

This patch fixes both problems by simply returning the true
displacement value (in its original type).  This doesn't
affect any other user of the displacement.


Added:
    llvm/trunk/test/CodeGen/PowerPC/2013-05-15-preinc-fold.ll
Modified:
    llvm/trunk/lib/Target/PowerPC/PPCISelLowering.cpp

Modified: llvm/trunk/lib/Target/PowerPC/PPCISelLowering.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Target/PowerPC/PPCISelLowering.cpp?rev=182012&r1=182011&r2=182012&view=diff
==============================================================================
--- llvm/trunk/lib/Target/PowerPC/PPCISelLowering.cpp (original)
+++ llvm/trunk/lib/Target/PowerPC/PPCISelLowering.cpp Thu May 16 09:53:05 2013
@@ -1061,7 +1061,7 @@ bool PPCTargetLowering::SelectAddressReg
   if (N.getOpcode() == ISD::ADD) {
     short imm = 0;
     if (isIntS16Immediate(N.getOperand(1), imm)) {
-      Disp = DAG.getTargetConstant((int)imm & 0xFFFF, MVT::i32);
+      Disp = DAG.getTargetConstant(imm, N.getValueType());
       if (FrameIndexSDNode *FI = dyn_cast<FrameIndexSDNode>(N.getOperand(0))) {
         Base = DAG.getTargetFrameIndex(FI->getIndex(), N.getValueType());
       } else {
@@ -1093,7 +1093,7 @@ bool PPCTargetLowering::SelectAddressReg
         // If all of the bits are known zero on the LHS or RHS, the add won't
         // carry.
         Base = N.getOperand(0);
-        Disp = DAG.getTargetConstant((int)imm & 0xFFFF, MVT::i32);
+        Disp = DAG.getTargetConstant(imm, N.getValueType());
         return true;
       }
     }

Added: llvm/trunk/test/CodeGen/PowerPC/2013-05-15-preinc-fold.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/CodeGen/PowerPC/2013-05-15-preinc-fold.ll?rev=182012&view=auto
==============================================================================
--- llvm/trunk/test/CodeGen/PowerPC/2013-05-15-preinc-fold.ll (added)
+++ llvm/trunk/test/CodeGen/PowerPC/2013-05-15-preinc-fold.ll Thu May 16 09:53:05 2013
@@ -0,0 +1,19 @@
+; RUN: llc < %s | FileCheck %s
+
+target datalayout = "E-p:64:64:64-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:64:64-f32:32:32-f64:64:64-f128:128:128-v128:128:128-n32:64"
+target triple = "powerpc64-unknown-linux-gnu"
+
+define i8* @test(i8* %base, i8 %val) {
+entry:
+  %arrayidx = getelementptr inbounds i8* %base, i32 -1
+  store i8 %val, i8* %arrayidx, align 1
+  %arrayidx2 = getelementptr inbounds i8* %base, i32 1
+  store i8 %val, i8* %arrayidx2, align 1
+  ret i8* %arrayidx
+}
+; CHECK: @test
+; CHECK: %entry
+; CHECK-NEXT: stbu 4, -1(3)
+; CHECK-NEXT: stb 4, 2(3)
+; CHECK-NEXT: blr
+





More information about the llvm-commits mailing list