From 328ef89bd1d7f725e68050063acb982411fc1df4 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. llvm-svn: 85738 --- .../Scalar/InstructionCombining.cpp | 2 +- llvm/test/Transforms/InstCombine/phi.ll | 26 +++++++++++++++++++ 2 files changed, 27 insertions(+), 1 deletion(-) diff --git a/llvm/lib/Transforms/Scalar/InstructionCombining.cpp b/llvm/lib/Transforms/Scalar/InstructionCombining.cpp index 4c6c2bb2ac8c..07681d15d876 100644 --- a/llvm/lib/Transforms/Scalar/InstructionCombining.cpp +++ b/llvm/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/llvm/test/Transforms/InstCombine/phi.ll b/llvm/test/Transforms/InstCombine/phi.ll index 08d28b4de7ef..d5665f6b68c3 100644 --- a/llvm/test/Transforms/InstCombine/phi.ll +++ b/llvm/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 + +} +