From a664bb7bdcc074cb03a2fa6ed1c52a2ca9453550 Mon Sep 17 00:00:00 2001 From: Chris Lattner Date: Sun, 1 Nov 2009 20:07:07 +0000 Subject: [PATCH] when merging two loads, make sure to take the min of their alignment, not the max. This didn't matter until the previous patch because instcombine would refuse to sink loads with differenting alignments. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@85738 91177308-0d34-0410-b5e6-96231b3b80d8 --- .../Scalar/InstructionCombining.cpp | 2 +- test/Transforms/InstCombine/phi.ll | 26 +++++++++++++++++++ 2 files changed, 27 insertions(+), 1 deletion(-) diff --git a/lib/Transforms/Scalar/InstructionCombining.cpp b/lib/Transforms/Scalar/InstructionCombining.cpp index 4c6c2bb2ac8..07681d15d87 100644 --- a/lib/Transforms/Scalar/InstructionCombining.cpp +++ b/lib/Transforms/Scalar/InstructionCombining.cpp @@ -10774,7 +10774,7 @@ Instruction *InstCombiner::FoldPHIArgLoadIntoPHI(PHINode &PN) { if ((LoadAlignment != 0) != (LI->getAlignment() != 0)) return 0; - LoadAlignment = std::max(LoadAlignment, LI->getAlignment()); + LoadAlignment = std::min(LoadAlignment, LI->getAlignment()); // If the PHI is of volatile loads and the load block has multiple // successors, sinking it would remove a load of the volatile value from diff --git a/test/Transforms/InstCombine/phi.ll b/test/Transforms/InstCombine/phi.ll index 08d28b4de7e..d5665f6b68c 100644 --- a/test/Transforms/InstCombine/phi.ll +++ b/test/Transforms/InstCombine/phi.ll @@ -157,9 +157,35 @@ bb1: bb2: %E = phi i32 [ %C, %bb ], [ %D, %bb1 ] ret i32 %E +; CHECK: @test9 ; CHECK: bb2: ; CHECK-NEXT: phi i32* [ %B, %bb ], [ %A, %bb1 ] ; CHECK-NEXT: %E = load i32* %{{[^,]*}}, align 1 ; CHECK-NEXT: ret i32 %E } + +define i32 @test10(i32* %A, i32* %B) { +entry: + %c = icmp eq i32* %A, null + br i1 %c, label %bb1, label %bb + +bb: + %C = load i32* %B, align 16 + br label %bb2 + +bb1: + %D = load i32* %A, align 32 + br label %bb2 + +bb2: + %E = phi i32 [ %C, %bb ], [ %D, %bb1 ] + ret i32 %E +; CHECK: @test10 +; CHECK: bb2: +; CHECK-NEXT: phi i32* [ %B, %bb ], [ %A, %bb1 ] +; CHECK-NEXT: %E = load i32* %{{[^,]*}}, align 16 +; CHECK-NEXT: ret i32 %E + +} +