Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
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
7 changes: 5 additions & 2 deletions llvm/lib/CodeGen/SelectionDAG/TargetLowering.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4462,11 +4462,14 @@ static SDValue foldSetCCWithFunnelShift(EVT VT, SDValue N0, SDValue N1,

unsigned BitWidth = N0.getScalarValueSizeInBits();
auto *ShAmtC = isConstOrConstSplat(N0.getOperand(2));
if (!ShAmtC || ShAmtC->getAPIntValue().uge(BitWidth))
if (!ShAmtC)
return SDValue();

uint64_t ShAmt = ShAmtC->getAPIntValue().urem(BitWidth);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Doesn't this need a .getZExtValue to convert from APInt to uint64_t?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

urem(uint64_t) returns a uint64_t

if (ShAmt == 0)
return SDValue();
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why not:

uint64_t AmtVal = ShAmtC->getAPIntValue().urem(BitWidth);
if (AmtVal == 0)
  return SDValue();

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

From my point of view - just because it should not come up from non-canonical code IIUC, and so fixing the bug is the more important issue and trying to handle other cases that could lead to further bugs for little benefit. But it sounds OK so long as the rest of the code handles it correctly.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@RKSimon You're right. It's OK to take the modulo first. I've fixed it. Thanks!


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

Expand Down
24 changes: 24 additions & 0 deletions llvm/test/CodeGen/AArch64/setcc-fsh.ll
Original file line number Diff line number Diff line change
Expand Up @@ -248,3 +248,27 @@ define i1 @fshl_or_ne_2(i32 %x, i32 %y) {
%r = icmp ne i32 %f, 2
ret i1 %r
}

define i1 @fshr_0_or_eq_0(i16 %x, i16 %y) {
; CHECK-LABEL: fshr_0_or_eq_0:
; CHECK: // %bb.0:
; CHECK-NEXT: tst w0, #0xffff
; CHECK-NEXT: cset w0, eq
; CHECK-NEXT: ret
%or = or i16 %x, %y
%f = call i16 @llvm.fshr.i16(i16 %or, i16 %x, i16 0)
%r = icmp eq i16 %f, 0
ret i1 %r
}

define i1 @fshr_32_or_eq_0(i16 %x, i16 %y) {
; CHECK-LABEL: fshr_32_or_eq_0:
; CHECK: // %bb.0:
; CHECK-NEXT: tst w0, #0xffff
; CHECK-NEXT: cset w0, eq
; CHECK-NEXT: ret
%or = or i16 %x, %y
%f = call i16 @llvm.fshr.i16(i16 %or, i16 %x, i16 32)
%r = icmp eq i16 %f, 0
ret i1 %r
}