Skip to content

Commit 4835941

Browse files
committed
fix
1 parent 9f292d7 commit 4835941

File tree

2 files changed

+25
-1
lines changed

2 files changed

+25
-1
lines changed

llvm/lib/Target/AArch64/AArch64ISelLowering.cpp

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26372,8 +26372,15 @@ static SDValue performSHLCombine(SDNode *N,
2637226372

2637326373
SDLoc DL(N);
2637426374
EVT VT = N->getValueType(0);
26375-
SDValue X = Op0->getOperand(0);
26375+
26376+
// Don't combine unless (shl C1, C2) can be constant folded. Otherwise,
26377+
// DAGCombiner will simplify (and (op x...), (op y...)) -> (op (and x, y))
26378+
// causing infinite loop. Result may also be worse.
2637626379
SDValue NewRHS = DAG.getNode(ISD::SHL, DL, VT, C1, C2);
26380+
if (!isa<ConstantSDNode>(NewRHS))
26381+
return SDValue();
26382+
26383+
SDValue X = Op0->getOperand(0);
2637726384
SDValue NewShift = DAG.getNode(ISD::SHL, DL, VT, X, C2);
2637826385
return DAG.getNode(ISD::AND, DL, VT, NewShift, NewRHS);
2637926386
}

llvm/test/CodeGen/AArch64/xbfiz.ll

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,3 +85,20 @@ define i64 @lsl_zext_i16_i64(i16 %b) {
8585
%2 = shl i64 %1, 1
8686
ret i64 %2
8787
}
88+
89+
; Regression test for:
90+
; https://github.com/llvm/llvm-project/pull/118974#issuecomment-2598521878
91+
; that exposed infinite loop in DAGCombiner.
92+
define void @_f(ptr %0, ptr %1, i64 %2) {
93+
; CHECK-LABEL: @_f
94+
store i64 -2401053089408754003, ptr %1, align 8
95+
%4 = and i64 %2, -2401053089408754003
96+
%5 = shl i64 %4, 1
97+
store i64 %5, ptr %0, align 1
98+
%6 = lshr i64 %4, 54
99+
%7 = shl i64 %2, 10
100+
%8 = and i64 %7, 131072
101+
%9 = or i64 %8, %6
102+
store i64 %9, ptr %1, align 1
103+
ret void
104+
}

0 commit comments

Comments
 (0)