summaryrefslogtreecommitdiffstats
path: root/llvm/lib
diff options
context:
space:
mode:
authorDuncan Sands <baldrick@free.fr>2012-11-16 18:55:49 +0000
committerDuncan Sands <baldrick@free.fr>2012-11-16 18:55:49 +0000
commit1d3acddf0e9b49ad3d489aafc61ea90c71724ba2 (patch)
tree47b3c141f9d068bcfabeea19ea34027cd96914b7 /llvm/lib
parent98f57cacaecb278c702612f1cf0c3d9a280b072d (diff)
downloadbcm5719-llvm-1d3acddf0e9b49ad3d489aafc61ea90c71724ba2.tar.gz
bcm5719-llvm-1d3acddf0e9b49ad3d489aafc61ea90c71724ba2.zip
Fix PR14361: wrong simplification of A+B==B+A. You may think that the old logic
replaced by this patch is equivalent to the new logic, but you'd be wrong, and that's exactly where the bug was. There's a similar bug in instsimplify which manifests itself as instsimplify failing to simplify this, rather than doing it wrong, see next commit. llvm-svn: 168181
Diffstat (limited to 'llvm/lib')
-rw-r--r--llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp16
1 files changed, 14 insertions, 2 deletions
diff --git a/llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp b/llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp
index 8cb4a59cba9..e223a049f0b 100644
--- a/llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp
+++ b/llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp
@@ -2356,8 +2356,20 @@ Instruction *InstCombiner::visitICmpInst(ICmpInst &I) {
// Try not to increase register pressure.
BO0->hasOneUse() && BO1->hasOneUse()) {
// Determine Y and Z in the form icmp (X+Y), (X+Z).
- Value *Y = (A == C || A == D) ? B : A;
- Value *Z = (C == A || C == B) ? D : C;
+ Value *Y, *Z;
+ if (A == C) {
+ Y = B;
+ Z = D;
+ } else if (A == D) {
+ Y = B;
+ Z = C;
+ } else if (B == C) {
+ Y = A;
+ Z = D;
+ } else if (B == D) {
+ Y = A;
+ Z = C;
+ }
return new ICmpInst(Pred, Y, Z);
}
OpenPOWER on IntegriCloud