Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 8 additions & 1 deletion llvm/lib/Target/AArch64/AArch64ISelLowering.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26372,8 +26372,15 @@ static SDValue performSHLCombine(SDNode *N,

SDLoc DL(N);
EVT VT = N->getValueType(0);
SDValue X = Op0->getOperand(0);

// Don't combine unless (shl C1, C2) can be constant folded. Otherwise,
// DAGCombiner will simplify (and (op x...), (op y...)) -> (op (and x, y))
// causing infinite loop. Result may also be worse.
SDValue NewRHS = DAG.getNode(ISD::SHL, DL, VT, C1, C2);
if (!isa<ConstantSDNode>(NewRHS))
return SDValue();

SDValue X = Op0->getOperand(0);
SDValue NewShift = DAG.getNode(ISD::SHL, DL, VT, X, C2);
return DAG.getNode(ISD::AND, DL, VT, NewShift, NewRHS);
}
Expand Down
17 changes: 17 additions & 0 deletions llvm/test/CodeGen/AArch64/xbfiz.ll
Original file line number Diff line number Diff line change
Expand Up @@ -85,3 +85,20 @@ define i64 @lsl_zext_i16_i64(i16 %b) {
%2 = shl i64 %1, 1
ret i64 %2
}

; Regression test for:
; https://github.com/llvm/llvm-project/pull/118974#issuecomment-2598521878
; that exposed infinite loop in DAGCombiner.
define void @_f(ptr %0, ptr %1, i64 %2) {
; CHECK-LABEL: @_f
store i64 -2401053089408754003, ptr %1, align 8
%4 = and i64 %2, -2401053089408754003
%5 = shl i64 %4, 1
store i64 %5, ptr %0, align 1
%6 = lshr i64 %4, 54
%7 = shl i64 %2, 10
%8 = and i64 %7, 131072
%9 = or i64 %8, %6
store i64 %9, ptr %1, align 1
ret void
}
Loading