Fans were stunned when Loki was killed ten minutes into Avengers: Infinity War, but Tom Hiddleston had known about it for two years.
During an appearance at Seattle's Ace Comic Con 2018, Hiddleston said that, unlike his fellow Infinity War actors, he wasn't kept in the dark about what would happen to his character in the movie (via ComicBook). In fact, Joe and Anthony Russo told him about Loki's fate before he started shooting Taika Waititi's Thor: Ragnarok:
So, I've known about that scene for two years. I met with Marvel in May 2016, and they were actually telling me the story of Ragnarok with concept art and images. The Russos came in, and I introduced myself. So all four of us sat down, and they said, “This is how Infinity War begins. My whole journey through making Thor: Ragnarok "” I knew this was coming. By the end of Thor: Ragnarok, Loki has been accepted as Thor's brother again.
After Thanos choked Loki to death in Infinity War, he said, "No resurrections this time." But fans theorize that the God of Mischief didn't actually die, and that would leave the door open for him to return in a more significant role in Avengers 4. However, Hiddleston’s comments apparently indicate that the Mad Titan wasn’t exaggerating at all:
When I came to shoot the scene in Infinity War, I think it's very powerful that he calls himself an Odinson, and that closes the whole journey of Loki and what he can do. It [Loki’s death] set the stakes up emotionally. It takes the stakes up dramatically. You know that Thanos is someone who's more dangerous than anyone we've seen before.
Even so, based on some set photos of Hiddleston and Robert Downey Jr. that seem to hint at some sort of time travel, we’re fairly certain that Loki will return in Avengers 4. But we’ll have to wait until May 3, 2019 to find out for sure!