aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChris Lattner <sabre@nondot.org>2009-11-01 20:07:07 +0000
committerChris Lattner <sabre@nondot.org>2009-11-01 20:07:07 +0000
commita664bb7bdcc074cb03a2fa6ed1c52a2ca9453550 (patch)
tree4326efaab57032efbbc2fe022c1e7407c1a816e5
parent751a362c22ed5e08aafbc8f243f7aac3203189f8 (diff)
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
-rw-r--r--lib/Transforms/Scalar/InstructionCombining.cpp2
-rw-r--r--test/Transforms/InstCombine/phi.ll26
2 files changed, 27 insertions, 1 deletions
diff --git a/lib/Transforms/Scalar/InstructionCombining.cpp b/lib/Transforms/Scalar/InstructionCombining.cpp
index 4c6c2bb2ac..07681d15d8 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 08d28b4de7..d5665f6b68 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
+
+}
+