[mips][FastISel] Allow computation of addresses from constant expressions.
authorVasileios Kalintiris <Vasileios.Kalintiris@imgtec.com>
Tue, 12 May 2015 12:08:31 +0000 (12:08 +0000)
committerVasileios Kalintiris <Vasileios.Kalintiris@imgtec.com>
Tue, 12 May 2015 12:08:31 +0000 (12:08 +0000)
Summary:
Try to compute addresses when the offset from a memory location is a constant
expression.

Based on a patch by Reed Kotler.

Test Plan:
Passes test-suite for -O0/O2 and mips 32 r1/r2

Reviewers: rkotler, dsanders

Subscribers: llvm-commits, aemerson, rfuhler

Differential Revision: http://reviews.llvm.org/D6767

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@237117 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Target/Mips/MipsFastISel.cpp
test/CodeGen/Mips/Fast-ISel/constexpr-address.ll [new file with mode: 0644]

index 671f7e90b357b6526400f15388a141bb6677a534..95257b91917880607b47667abff045bfa225188f 100644 (file)
@@ -390,8 +390,10 @@ bool MipsFastISel::computeAddress(const Value *Obj, Address &Addr) {
       Opcode = I->getOpcode();
       U = I;
     }
-  } else if (isa<ConstantExpr>(Obj))
-    return false;
+  } else if (const ConstantExpr *C = dyn_cast<ConstantExpr>(Obj)) {
+    Opcode = C->getOpcode();
+    U = C;
+  }
   switch (Opcode) {
   default:
     break;
diff --git a/test/CodeGen/Mips/Fast-ISel/constexpr-address.ll b/test/CodeGen/Mips/Fast-ISel/constexpr-address.ll
new file mode 100644 (file)
index 0000000..df60d80
--- /dev/null
@@ -0,0 +1,18 @@
+; RUN: llc -march=mipsel -mcpu=mips32 -relocation-model=pic \
+; RUN:     -fast-isel=true -mips-fast-isel -fast-isel-abort=1 < %s | FileCheck %s
+; RUN: llc -march=mipsel -mcpu=mips32r2 -relocation-model=pic \
+; RUN:     -fast-isel=true -mips-fast-isel -fast-isel-abort=1 < %s | FileCheck %s
+
+@ARR = external global [10 x i32], align 4
+
+define void @foo() {
+; CHECK-LABEL: foo
+
+; CHECK-DAG:    lw      $[[ARR:[0-9]+]], %got(ARR)({{.*}})
+; CHECK-DAG:    addiu   $[[T0:[0-9]+]], $zero, 12345
+; CHECK:        sw      $[[T0]], 8($[[ARR]])
+
+entry:
+  store i32 12345, i32* getelementptr inbounds ([10 x i32], [10 x i32]* @ARR, i32 0, i32 2), align 4
+  ret void
+}