GlobalISel: place constants correctly in the entry block.
authorTim Northover <tnorthover@apple.com>
Mon, 5 Dec 2016 22:40:13 +0000 (22:40 +0000)
committerTim Northover <tnorthover@apple.com>
Mon, 5 Dec 2016 22:40:13 +0000 (22:40 +0000)
When the entry block was empty after arg lowering, we were always placing
constants at the end. This is probably hamrless while translating the same
block, but horribly wrong once its terminator has been translated. So switch to
inserting at the beginning.

llvm-svn: 288720

llvm/lib/CodeGen/GlobalISel/IRTranslator.cpp
llvm/test/CodeGen/AArch64/GlobalISel/arm64-irtranslator.ll
llvm/test/CodeGen/AArch64/GlobalISel/call-translator-ios.ll
llvm/test/CodeGen/AArch64/GlobalISel/call-translator.ll

index 1c0020e..68fec1a 100644 (file)
@@ -766,7 +766,7 @@ bool IRTranslator::runOnMachineFunction(MachineFunction &MF) {
   // Now that we've got the ABI handling code, it's safe to set a location for
   // any Constants we find in the IR.
   if (MBB.empty())
-    EntryBuilder.setMBB(MBB);
+    EntryBuilder.setMBB(MBB, /* Beginning */ true);
   else
     EntryBuilder.setInstr(MBB.back(), /* Before */ false);
 
index 0413d08..f9ef784 100644 (file)
@@ -1,4 +1,4 @@
-; RUN: llc -O0 -stop-after=irtranslator -global-isel -verify-machineinstrs %s -o - 2>&1 | FileCheck %s
+; RUN: llc -O0 -aarch64-enable-atomic-cfg-tidy=0 -stop-after=irtranslator -global-isel -verify-machineinstrs %s -o - 2>&1 | FileCheck %s
 
 ; This file checks that the translation from llvm IR to generic MachineInstr
 ; is correct.
@@ -383,8 +383,8 @@ next:
 }
 
 ; CHECK-LABEL: name: constant_int_start
-; CHECK: [[TWO:%[0-9]+]](s32) = G_CONSTANT i32 2
 ; CHECK: [[ANSWER:%[0-9]+]](s32) = G_CONSTANT i32 42
+; CHECK: [[TWO:%[0-9]+]](s32) = G_CONSTANT i32 2
 ; CHECK: [[RES:%[0-9]+]](s32) = G_ADD [[TWO]], [[ANSWER]]
 define i32 @constant_int_start() {
   %res = add i32 2, 42
@@ -915,3 +915,17 @@ define void @test_large_const(i128* %addr) {
   store i128 42, i128* %addr
   ret void
 }
+
+; When there was no formal argument handling (so the first BB was empty) we used
+; to insert the constants at the end of the block, even if they were encountered
+; after the block's terminators had been emitted.
+define i32 @test_const_placement() {
+; CHECK-LABEL: name: test_const_placement
+; CHECK: [[VAL:%[0-9]+]](s32) = G_CONSTANT i32 42
+; CHECK: G_BR
+
+  br label %next
+
+next:
+  ret i32 42
+}
index 4e6b9ca..a340082 100644 (file)
@@ -18,8 +18,8 @@ define signext i8 @test_stack_slots([8 x i64], i8 signext %lhs, i8 signext %rhs)
 }
 
 ; CHECK-LABEL: name: test_call_stack
-; CHECK: [[C42:%[0-9]+]](s8) = G_CONSTANT i8 42
 ; CHECK: [[C12:%[0-9]+]](s8) = G_CONSTANT i8 12
+; CHECK: [[C42:%[0-9]+]](s8) = G_CONSTANT i8 42
 ; CHECK: [[SP:%[0-9]+]](p0) = COPY %sp
 ; CHECK: [[C42_OFFS:%[0-9]+]](s64) = G_CONSTANT i64 0
 ; CHECK: [[C42_LOC:%[0-9]+]](p0) = G_GEP [[SP]], [[C42_OFFS]](s64)
index 65001a4..37221e3 100644 (file)
@@ -162,9 +162,9 @@ define void @test_stack_slots([8 x i64], i64 %lhs, i64 %rhs, i64* %addr) {
 }
 
 ; CHECK-LABEL: name: test_call_stack
-; CHECK: [[C42:%[0-9]+]](s64) = G_CONSTANT i64 42
-; CHECK: [[C12:%[0-9]+]](s64) = G_CONSTANT i64 12
 ; CHECK: [[PTR:%[0-9]+]](p0) = G_CONSTANT i64 0
+; CHECK: [[C12:%[0-9]+]](s64) = G_CONSTANT i64 12
+; CHECK: [[C42:%[0-9]+]](s64) = G_CONSTANT i64 42
 ; CHECK: [[SP:%[0-9]+]](p0) = COPY %sp
 ; CHECK: [[C42_OFFS:%[0-9]+]](s64) = G_CONSTANT i64 0
 ; CHECK: [[C42_LOC:%[0-9]+]](p0) = G_GEP [[SP]], [[C42_OFFS]](s64)