Not sure how Loki's death can be described as "undignified". He did what he was never willing to do before - sacrifice his selfish pursuit of power to save his brother, and then tried to make good by his misdeeds by attacking Thanos himself. After what happened in New York, and the certain threat upon his life by Thanos and The Other, he knew there was no way he was making it out alive. Unfortunately, in saving his brother and proving himself to be more than just the God of Mischief, he periled the universe. Dying to conceal The Tesseract was the 'greater good'.