aboutsummaryrefslogtreecommitdiff
path: root/llvm/lib/Analysis/ScalarEvolution.cpp
diff options
context:
space:
mode:
authorNikita Popov <npopov@redhat.com>2023-12-05 17:01:46 +0100
committerGitHub <noreply@github.com>2023-12-05 17:01:46 +0100
commitff0e4fb89a75ebe5f30a0292caba1ff88c8bff88 (patch)
tree3b78e9524ec1cc575c9f415002ddb90878ecd179 /llvm/lib/Analysis/ScalarEvolution.cpp
parent64a9b355fea89ced300e36108d6eb5a4f0fcd93a (diff)
downloadllvm-ff0e4fb89a75ebe5f30a0292caba1ff88c8bff88.zip
llvm-ff0e4fb89a75ebe5f30a0292caba1ff88c8bff88.tar.gz
llvm-ff0e4fb89a75ebe5f30a0292caba1ff88c8bff88.tar.bz2
[SCEV] Use or disjoint flag (#74467)
Use the disjoint flag to convert or to add instead of calling the haveNoCommonBitsSet() ValueTracking query. This ensures that we can reliably undo add -> or canonicalization, even in cases where the necessary information has been lost or is too complex to reinfer in SCEV. I have updated the bulk of the test coverage to add the necessary disjoint flags in advance.
Diffstat (limited to 'llvm/lib/Analysis/ScalarEvolution.cpp')
-rw-r--r--llvm/lib/Analysis/ScalarEvolution.cpp7
1 files changed, 2 insertions, 5 deletions
diff --git a/llvm/lib/Analysis/ScalarEvolution.cpp b/llvm/lib/Analysis/ScalarEvolution.cpp
index 9670e53..451ae73 100644
--- a/llvm/lib/Analysis/ScalarEvolution.cpp
+++ b/llvm/lib/Analysis/ScalarEvolution.cpp
@@ -5223,11 +5223,8 @@ static std::optional<BinaryOp> MatchBinaryOp(Value *V, const DataLayout &DL,
return BinaryOp(Op);
case Instruction::Or: {
- // LLVM loves to convert `add` of operands with no common bits
- // into an `or`. But SCEV really doesn't deal with `or` that well,
- // so try extra hard to recognize this `or` as an `add`.
- if (haveNoCommonBitsSet(Op->getOperand(0), Op->getOperand(1),
- SimplifyQuery(DL, &DT, &AC, CxtI)))
+ // Convert or disjoint into add nuw nsw.
+ if (cast<PossiblyDisjointInst>(Op)->isDisjoint())
return BinaryOp(Instruction::Add, Op->getOperand(0), Op->getOperand(1),
/*IsNSW=*/true, /*IsNUW=*/true);
return BinaryOp(Op);