From: Tim Northover Date: Mon, 5 Dec 2016 22:40:13 +0000 (+0000) Subject: GlobalISel: place constants correctly in the entry block. X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=9fef274c6a4eb39c77c507cc5602445de49206f3;p=llvm GlobalISel: place constants correctly in the entry block. 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. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@288720 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/lib/CodeGen/GlobalISel/IRTranslator.cpp b/lib/CodeGen/GlobalISel/IRTranslator.cpp index 1c0020ee693..68fec1a555f 100644 --- a/lib/CodeGen/GlobalISel/IRTranslator.cpp +++ b/lib/CodeGen/GlobalISel/IRTranslator.cpp @@ -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); diff --git a/test/CodeGen/AArch64/GlobalISel/arm64-irtranslator.ll b/test/CodeGen/AArch64/GlobalISel/arm64-irtranslator.ll index 0413d08a8bf..f9ef78470eb 100644 --- a/test/CodeGen/AArch64/GlobalISel/arm64-irtranslator.ll +++ b/test/CodeGen/AArch64/GlobalISel/arm64-irtranslator.ll @@ -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 +} diff --git a/test/CodeGen/AArch64/GlobalISel/call-translator-ios.ll b/test/CodeGen/AArch64/GlobalISel/call-translator-ios.ll index 4e6b9cad4c3..a340082d562 100644 --- a/test/CodeGen/AArch64/GlobalISel/call-translator-ios.ll +++ b/test/CodeGen/AArch64/GlobalISel/call-translator-ios.ll @@ -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) diff --git a/test/CodeGen/AArch64/GlobalISel/call-translator.ll b/test/CodeGen/AArch64/GlobalISel/call-translator.ll index 65001a48d97..37221e37b67 100644 --- a/test/CodeGen/AArch64/GlobalISel/call-translator.ll +++ b/test/CodeGen/AArch64/GlobalISel/call-translator.ll @@ -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)