Skip to content

Commit b062aad

Browse files
authored
[CodeGen] Drop disjoint flag when reassociating (#156218)
This fixes a latent miscompile. To understand why the flag can't be preserved, consider the case where a0=0, a1=0, a2=-1, and s3=-1.
1 parent 7730ebc commit b062aad

File tree

2 files changed

+4
-2
lines changed

2 files changed

+4
-2
lines changed

llvm/lib/CodeGen/TargetInstrInfo.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1456,11 +1456,13 @@ void TargetInstrInfo::reassociateOps(
14561456
MIB1->clearFlag(MachineInstr::MIFlag::NoSWrap);
14571457
MIB1->clearFlag(MachineInstr::MIFlag::NoUWrap);
14581458
MIB1->clearFlag(MachineInstr::MIFlag::IsExact);
1459+
MIB1->clearFlag(MachineInstr::MIFlag::Disjoint);
14591460

14601461
MIB2->setFlags(IntersectedFlags);
14611462
MIB2->clearFlag(MachineInstr::MIFlag::NoSWrap);
14621463
MIB2->clearFlag(MachineInstr::MIFlag::NoUWrap);
14631464
MIB2->clearFlag(MachineInstr::MIFlag::IsExact);
1465+
MIB2->clearFlag(MachineInstr::MIFlag::Disjoint);
14641466

14651467
setSpecialOperandAttr(Root, Prev, *MIB1, *MIB2);
14661468

llvm/test/CodeGen/RISCV/machine-combiner-mir.ll

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -116,8 +116,8 @@ define i64 @test_or_flags(i64 %a0, i64 %a1, i64 %a2, i64 %a3) {
116116
; CHECK-NEXT: [[COPY2:%[0-9]+]]:gpr = COPY $x11
117117
; CHECK-NEXT: [[COPY3:%[0-9]+]]:gpr = COPY $x10
118118
; CHECK-NEXT: [[OR:%[0-9]+]]:gpr = OR [[COPY3]], [[COPY2]]
119-
; CHECK-NEXT: [[OR1:%[0-9]+]]:gpr = disjoint OR [[COPY1]], [[COPY]]
120-
; CHECK-NEXT: [[OR2:%[0-9]+]]:gpr = disjoint OR killed [[OR]], killed [[OR1]]
119+
; CHECK-NEXT: [[OR1:%[0-9]+]]:gpr = OR [[COPY1]], [[COPY]]
120+
; CHECK-NEXT: [[OR2:%[0-9]+]]:gpr = OR killed [[OR]], killed [[OR1]]
121121
; CHECK-NEXT: $x10 = COPY [[OR2]]
122122
; CHECK-NEXT: PseudoRET implicit $x10
123123
%t0 = or i64 %a0, %a1

0 commit comments

Comments
 (0)