llvm.org GIT mirror llvm / 5fb3c84
Retain alignment requirements for load->selects modified by DAGCombine DAGCombine may choose to rewrite graphs where two loads feed a select into graphs where a select of two addresses feed a load. While it sanity checks the loads to make sure they are broadly equivalent it currently just uses the alignment restriction of the left node. In cases where the right node has stronger alignment requiresment this may lead to bad codegen, such as generating an aligned load where an unaligned load is required. This patch makes the combine generate a load with an alignment that is the same as whichever is more restrictive of the two alignments. Tests included. rdar://17762530 git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@214322 91177308-0d34-0410-b5e6-96231b3b80d8 Louis Gerbarg 5 years ago
2 changed file(s) with 41 addition(s) and 2 deletion(s). Raw diff Collapse all Expand all
1118011180 }
1118111181
1118211182 SDValue Load;
11183 // It is safe to replace the two loads if they have different alignments,
11184 // but the new load must be the minimum (most restrictive) alignment of the
11185 // inputs.
11186 unsigned Alignment = std::min(LLD->getAlignment(),RLD->getAlignment());
1118311187 if (LLD->getExtensionType() == ISD::NON_EXTLOAD) {
1118411188 Load = DAG.getLoad(TheSelect->getValueType(0),
1118511189 SDLoc(TheSelect),
1118611190 // FIXME: Discards pointer and AA info.
1118711191 LLD->getChain(), Addr, MachinePointerInfo(),
1118811192 LLD->isVolatile(), LLD->isNonTemporal(),
11189 LLD->isInvariant(), LLD->getAlignment());
11193 LLD->isInvariant(), Alignment);
1119011194 } else {
1119111195 Load = DAG.getExtLoad(LLD->getExtensionType() == ISD::EXTLOAD ?
1119211196 RLD->getExtensionType() : LLD->getExtensionType(),
1119511199 // FIXME: Discards pointer and AA info.
1119611200 LLD->getChain(), Addr, MachinePointerInfo(),
1119711201 LLD->getMemoryVT(), LLD->isVolatile(),
11198 LLD->isNonTemporal(), LLD->getAlignment());
11202 LLD->isNonTemporal(), Alignment);
1119911203 }
1120011204
1120111205 // Users of the select now use the result of the load.
0 ; RUN: llc -mcpu=core2 -mattr=+64bit,+sse2 < %s | FileCheck %s
1
2 ; DAGCombine may choose to rewrite 2 loads feeding a select as a select of
3 ; addresses feeding a load. This test ensures that when it does that it creates
4 ; a load with alignment equivalent to the most restrictive source load.
5
6 declare void @sink(<2 x double>)
7
8 define void @test1(i1 %cmp) align 2 {
9 %1 = alloca <2 x double>, align 16
10 %2 = alloca <2 x double>, align 8
11
12 %val = load <2 x double>* %1, align 16
13 %val2 = load <2 x double>* %2, align 8
14 %val3 = select i1 %cmp, <2 x double> %val, <2 x double> %val2
15 call void @sink(<2 x double> %val3)
16 ret void
17 ; CHECK: test1
18 ; CHECK: movups
19 ; CHECK: ret
20 }
21
22 define void @test2(i1 %cmp) align 2 {
23 %1 = alloca <2 x double>, align 16
24 %2 = alloca <2 x double>, align 8
25
26 %val = load <2 x double>* %1, align 16
27 %val2 = load <2 x double>* %2, align 16
28 %val3 = select i1 %cmp, <2 x double> %val, <2 x double> %val2
29 call void @sink(<2 x double> %val3)
30 ret void
31 ; CHECK: test2
32 ; CHECK: movaps
33 ; CHECK: ret
34 }