xref: /aosp_15_r20/external/llvm/test/CodeGen/X86/sext-load.ll (revision 9880d6810fe72a1726cb53787c6711e909410d58)
1*9880d681SAndroid Build Coastguard Worker; RUN: llc < %s -march=x86 | FileCheck %s
2*9880d681SAndroid Build Coastguard Worker
3*9880d681SAndroid Build Coastguard Worker; When doing sign extension, use the sext-load lowering to take advantage of
4*9880d681SAndroid Build Coastguard Worker; x86's sign extension during loads.
5*9880d681SAndroid Build Coastguard Worker;
6*9880d681SAndroid Build Coastguard Worker; CHECK-LABEL: test1:
7*9880d681SAndroid Build Coastguard Worker; CHECK:      movsbl {{.*}}, %eax
8*9880d681SAndroid Build Coastguard Worker; CHECK-NEXT: ret
9*9880d681SAndroid Build Coastguard Workerdefine i32 @test1(i32 %X) nounwind  {
10*9880d681SAndroid Build Coastguard Workerentry:
11*9880d681SAndroid Build Coastguard Worker	%tmp12 = trunc i32 %X to i8		; <i8> [#uses=1]
12*9880d681SAndroid Build Coastguard Worker	%tmp123 = sext i8 %tmp12 to i32		; <i32> [#uses=1]
13*9880d681SAndroid Build Coastguard Worker	ret i32 %tmp123
14*9880d681SAndroid Build Coastguard Worker}
15*9880d681SAndroid Build Coastguard Worker
16*9880d681SAndroid Build Coastguard Worker; When using a sextload representation, ensure that the sign extension is
17*9880d681SAndroid Build Coastguard Worker; preserved even when removing shifted-out low bits.
18*9880d681SAndroid Build Coastguard Worker;
19*9880d681SAndroid Build Coastguard Worker; CHECK-LABEL: test2:
20*9880d681SAndroid Build Coastguard Worker; CHECK:      movswl {{.*}}, %eax
21*9880d681SAndroid Build Coastguard Worker; CHECK-NEXT: ret
22*9880d681SAndroid Build Coastguard Workerdefine i32 @test2({i16, [6 x i8]}* %this) {
23*9880d681SAndroid Build Coastguard Workerentry:
24*9880d681SAndroid Build Coastguard Worker  %b48 = getelementptr inbounds { i16, [6 x i8] }, { i16, [6 x i8] }* %this, i32 0, i32 1
25*9880d681SAndroid Build Coastguard Worker  %cast = bitcast [6 x i8]* %b48 to i48*
26*9880d681SAndroid Build Coastguard Worker  %bf.load = load i48, i48* %cast, align 2
27*9880d681SAndroid Build Coastguard Worker  %bf.ashr = ashr i48 %bf.load, 32
28*9880d681SAndroid Build Coastguard Worker  %bf.cast = trunc i48 %bf.ashr to i32
29*9880d681SAndroid Build Coastguard Worker  ret i32 %bf.cast
30*9880d681SAndroid Build Coastguard Worker}
31