Skip to content

Commit 5658d86

Browse files
committed
AArch64: clamp UBFX high-bit to 32-bits
We were producing invalid instructions like "ubfx w0, w0, #20, #16".
1 parent aa9c2d1 commit 5658d86

File tree

2 files changed

+14
-0
lines changed

2 files changed

+14
-0
lines changed

llvm/lib/Target/AArch64/AArch64ISelDAGToDAG.cpp

+1
Original file line numberDiff line numberDiff line change
@@ -1852,6 +1852,7 @@ static bool isBitfieldExtractOpFromAnd(SelectionDAG *CurDAG, SDNode *N,
18521852
VT = Opd0->getValueType(0);
18531853
} else if (isOpcWithIntImmediate(Op0, ISD::SRL, SrlImm)) {
18541854
Opd0 = Op0->getOperand(0);
1855+
ClampMSB = (VT == MVT::i32);
18551856
} else if (BiggerPattern) {
18561857
// Let's pretend a 0 shift right has been performed.
18571858
// The resulting code will be at least as good as the original one

llvm/test/CodeGen/AArch64/bitfield.ll

+13
Original file line numberDiff line numberDiff line change
@@ -230,3 +230,16 @@ define dso_local i64 @test_sbfx64(i64* %addr) {
230230
%extended = ashr i64 %shifted, 1
231231
ret i64 %extended
232232
}
233+
234+
define i32 @test_ubfx_mask(i32 %lhs, i32 %rhs) {
235+
; CHECK-LABEL: test_ubfx_mask:
236+
; CHECK: lsr w0, w1, #20
237+
%mask = and i32 %lhs, 20
238+
%i7 = add i32 %mask, 1
239+
%i8 = xor i32 %lhs, 20
240+
%i9 = xor i32 %i8, %i7
241+
%i10 = and i32 %i9, 20
242+
%shift = lshr i32 %rhs, %i10
243+
%shift.masked = and i32 %shift, 65535
244+
ret i32 %shift.masked
245+
}

0 commit comments

Comments
 (0)