|
17 | 17 | #include "llvm/Analysis/AssumptionCache.h" |
18 | 18 | #include "llvm/Analysis/CmpInstAnalysis.h" |
19 | 19 | #include "llvm/Analysis/InstructionSimplify.h" |
| 20 | +#include "llvm/Analysis/Loads.h" |
20 | 21 | #include "llvm/Analysis/OverflowInstAnalysis.h" |
21 | 22 | #include "llvm/Analysis/ValueTracking.h" |
22 | 23 | #include "llvm/Analysis/VectorUtils.h" |
@@ -1411,6 +1412,8 @@ Instruction *InstCombinerImpl::foldSelectValueEquivalence(SelectInst &Sel, |
1411 | 1412 | // in the cmp and in f(Y). |
1412 | 1413 | if (TrueVal == OldOp && (isa<Constant>(OldOp) || !isa<Constant>(NewOp))) |
1413 | 1414 | return nullptr; |
| 1415 | + if (!canReplacePointersIfEqual(OldOp, NewOp, DL)) |
| 1416 | + return nullptr; |
1414 | 1417 |
|
1415 | 1418 | if (Value *V = simplifyWithOpReplaced(TrueVal, OldOp, NewOp, SQ, |
1416 | 1419 | /* AllowRefinement=*/true)) { |
@@ -1466,12 +1469,14 @@ Instruction *InstCombinerImpl::foldSelectValueEquivalence(SelectInst &Sel, |
1466 | 1469 | // Example: |
1467 | 1470 | // (X == 42) ? 43 : (X + 1) --> (X == 42) ? (X + 1) : (X + 1) --> X + 1 |
1468 | 1471 | SmallVector<Instruction *> DropFlags; |
1469 | | - if (simplifyWithOpReplaced(FalseVal, CmpLHS, CmpRHS, SQ, |
1470 | | - /* AllowRefinement */ false, |
1471 | | - &DropFlags) == TrueVal || |
1472 | | - simplifyWithOpReplaced(FalseVal, CmpRHS, CmpLHS, SQ, |
1473 | | - /* AllowRefinement */ false, |
1474 | | - &DropFlags) == TrueVal) { |
| 1472 | + if ((canReplacePointersIfEqual(CmpLHS, CmpRHS, DL) && |
| 1473 | + simplifyWithOpReplaced(FalseVal, CmpLHS, CmpRHS, SQ, |
| 1474 | + /* AllowRefinement */ false, |
| 1475 | + &DropFlags) == TrueVal) || |
| 1476 | + (canReplacePointersIfEqual(CmpRHS, CmpLHS, DL) && |
| 1477 | + simplifyWithOpReplaced(FalseVal, CmpRHS, CmpLHS, SQ, |
| 1478 | + /* AllowRefinement */ false, |
| 1479 | + &DropFlags) == TrueVal)) { |
1475 | 1480 | for (Instruction *I : DropFlags) { |
1476 | 1481 | I->dropPoisonGeneratingAnnotations(); |
1477 | 1482 | Worklist.add(I); |
|
0 commit comments