Skip to content

Commit cd8ae16

Browse files
committed
[SelectionDAG] Fix incorrect fold condition in foldSetCCWithFunnelShift.
1 parent 342c7e1 commit cd8ae16

File tree

2 files changed

+8
-4
lines changed

2 files changed

+8
-4
lines changed

llvm/lib/CodeGen/SelectionDAG/TargetLowering.cpp

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4462,11 +4462,14 @@ static SDValue foldSetCCWithFunnelShift(EVT VT, SDValue N0, SDValue N1,
44624462

44634463
unsigned BitWidth = N0.getScalarValueSizeInBits();
44644464
auto *ShAmtC = isConstOrConstSplat(N0.getOperand(2));
4465-
if (!ShAmtC || ShAmtC->getAPIntValue().uge(BitWidth))
4465+
if (!ShAmtC)
4466+
return SDValue();
4467+
4468+
uint64_t ShAmt = ShAmtC->getAPIntValue().urem(BitWidth);
4469+
if (ShAmt == 0)
44664470
return SDValue();
44674471

44684472
// Canonicalize fshr as fshl to reduce pattern-matching.
4469-
unsigned ShAmt = ShAmtC->getZExtValue();
44704473
if (N0.getOpcode() == ISD::FSHR)
44714474
ShAmt = BitWidth - ShAmt;
44724475

llvm/test/CodeGen/AArch64/setcc-fsh.ll

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -252,7 +252,8 @@ define i1 @fshl_or_ne_2(i32 %x, i32 %y) {
252252
define i1 @fshr_0_or_eq_0(i16 %x, i16 %y) {
253253
; CHECK-LABEL: fshr_0_or_eq_0:
254254
; CHECK: // %bb.0:
255-
; CHECK-NEXT: mov w0, wzr
255+
; CHECK-NEXT: tst w0, #0xffff
256+
; CHECK-NEXT: cset w0, eq
256257
; CHECK-NEXT: ret
257258
%or = or i16 %x, %y
258259
%f = call i16 @llvm.fshr.i16(i16 %or, i16 %x, i16 0)
@@ -261,7 +262,7 @@ define i1 @fshr_0_or_eq_0(i16 %x, i16 %y) {
261262
}
262263

263264
define i1 @fshr_32_or_eq_0(i16 %x, i16 %y) {
264-
; CHECK-LABEL: fshr_16_or_eq_0:
265+
; CHECK-LABEL: fshr_32_or_eq_0:
265266
; CHECK: // %bb.0:
266267
; CHECK-NEXT: tst w0, #0xffff
267268
; CHECK-NEXT: cset w0, eq

0 commit comments

Comments
 (0)