Skip to content

Commit 181baac

Browse files
nikicllvmbot
authored andcommitted
[SCEVExpander] Do not reuse disjoint or (llvm#80281)
SCEV treats "or disjoint" the same as "add nsw nuw". However, when expanding, we cannot generally replace an add SCEV node with an "or disjoint" instruction. Just dropping the poison flag is insufficient in this case, we would have to actually convert the or into an add. This is a partial fix for llvm#79861. (cherry picked from commit 5b8e1a6)
1 parent 2fa03f1 commit 181baac

File tree

2 files changed

+10
-2
lines changed

2 files changed

+10
-2
lines changed

llvm/lib/Transforms/Utils/ScalarEvolutionExpander.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1401,6 +1401,13 @@ canReuseInstruction(ScalarEvolution &SE, const SCEV *S, Instruction *I,
14011401
if (!I)
14021402
return false;
14031403

1404+
// Disjoint or instructions are interpreted as adds by SCEV. However, we
1405+
// can't replace an arbitrary add with disjoint or, even if we drop the
1406+
// flag. We would need to convert the or into an add.
1407+
if (auto *PDI = dyn_cast<PossiblyDisjointInst>(I))
1408+
if (PDI->isDisjoint())
1409+
return false;
1410+
14041411
// FIXME: Ignore vscale, even though it technically could be poison. Do this
14051412
// because SCEV currently assumes it can't be poison. Remove this special
14061413
// case once we proper model when vscale can be poison.

llvm/test/Transforms/IndVarSimplify/pr79861.ll

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -75,14 +75,15 @@ define void @expander_or_disjoint(i64 %n) {
7575
; CHECK-LABEL: define void @expander_or_disjoint(
7676
; CHECK-SAME: i64 [[N:%.*]]) {
7777
; CHECK-NEXT: entry:
78-
; CHECK-NEXT: [[OR:%.*]] = or i64 [[N]], 1
78+
; CHECK-NEXT: [[OR:%.*]] = or disjoint i64 [[N]], 1
79+
; CHECK-NEXT: [[TMP0:%.*]] = add i64 [[N]], 1
7980
; CHECK-NEXT: br label [[LOOP:%.*]]
8081
; CHECK: loop:
8182
; CHECK-NEXT: [[IV:%.*]] = phi i64 [ 0, [[ENTRY:%.*]] ], [ [[IV_INC:%.*]], [[LOOP]] ]
8283
; CHECK-NEXT: [[IV_INC]] = add i64 [[IV]], 1
8384
; CHECK-NEXT: [[ADD:%.*]] = add i64 [[IV]], [[OR]]
8485
; CHECK-NEXT: call void @use(i64 [[ADD]])
85-
; CHECK-NEXT: [[EXITCOND:%.*]] = icmp ne i64 [[IV_INC]], [[OR]]
86+
; CHECK-NEXT: [[EXITCOND:%.*]] = icmp ne i64 [[IV_INC]], [[TMP0]]
8687
; CHECK-NEXT: br i1 [[EXITCOND]], label [[LOOP]], label [[EXIT:%.*]]
8788
; CHECK: exit:
8889
; CHECK-NEXT: ret void

0 commit comments

Comments
 (0)