Don't fold address calculations which use negative offsets into
authorRichard Osborne <richard@xmos.com>
Thu, 15 Jan 2009 11:32:30 +0000 (11:32 +0000)
committerRichard Osborne <richard@xmos.com>
Thu, 15 Jan 2009 11:32:30 +0000 (11:32 +0000)
the ADDRspii addressing mode.

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

lib/Target/XCore/XCoreISelDAGToDAG.cpp
test/CodeGen/XCore/2009-01-08-Crash.ll [new file with mode: 0644]

index 28b501de7dd92a107be59c32cd7247dcdb05e273..684ef0bf1258c07d949196a3efb518098345f413 100644 (file)
@@ -92,8 +92,8 @@ bool XCoreDAGToDAGISel::SelectADDRspii(SDValue Op, SDValue Addr,
     ConstantSDNode *CN = 0;
     if ((FIN = dyn_cast<FrameIndexSDNode>(Addr.getOperand(0)))
       && (CN = dyn_cast<ConstantSDNode>(Addr.getOperand(1)))
-      && (CN->getSExtValue() % 4 == 0)) {
-      // Constant word offset from frame pointer
+      && (CN->getSExtValue() % 4 == 0 && CN->getSExtValue() >= 0)) {
+      // Constant positive word offset from frame index
       Base = CurDAG->getTargetFrameIndex(FIN->getIndex(), MVT::i32);
       Offset = CurDAG->getTargetConstant(CN->getSExtValue(), MVT::i32);
       return true;
diff --git a/test/CodeGen/XCore/2009-01-08-Crash.ll b/test/CodeGen/XCore/2009-01-08-Crash.ll
new file mode 100644 (file)
index 0000000..6f5fb7c
--- /dev/null
@@ -0,0 +1,12 @@
+; RUN: llvm-as < %s | llc -march=xcore > %t1.s
+;; This caused a compilation failure since the
+;; address arithmetic was folded into the LDWSP instruction,
+;; resulting in a negative offset which eliminateFrameIndex was
+;; unable to eliminate.
+define i32 @test(i32 %bar) nounwind readnone {
+entry:
+        %bar_addr = alloca i32
+        %0 = getelementptr i32* %bar_addr, i32 -1
+        %1 = load i32* %0, align 4
+        ret i32 %1
+}