Skip to content

Commit 1e49670

Browse files
authored
[DAGISel] Keep flags when converting FP load/store to integer (#111679)
This DAG combine replaces a floating-point load/store pair which has no other uses with an integer one, but did not copy the memory operand flags to the new instructions, resulting in it dropping the volatile flag. This optimisation is still valid if one or both of the instructions is volatile, so we can copy over the whole MachineMemOperand to generate volatile integer loads and stores where needed.
1 parent 1fa3c85 commit 1e49670

File tree

3 files changed

+33
-11
lines changed

3 files changed

+33
-11
lines changed

llvm/lib/CodeGen/SelectionDAG/DAGCombiner.cpp

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -20322,13 +20322,11 @@ SDValue DAGCombiner::TransformFPLoadStorePair(SDNode *N) {
2032220322
!FastLD || !FastST)
2032320323
return SDValue();
2032420324

20325-
SDValue NewLD =
20326-
DAG.getLoad(IntVT, SDLoc(Value), LD->getChain(), LD->getBasePtr(),
20327-
LD->getPointerInfo(), LD->getAlign());
20325+
SDValue NewLD = DAG.getLoad(IntVT, SDLoc(Value), LD->getChain(),
20326+
LD->getBasePtr(), LD->getMemOperand());
2032820327

20329-
SDValue NewST =
20330-
DAG.getStore(ST->getChain(), SDLoc(N), NewLD, ST->getBasePtr(),
20331-
ST->getPointerInfo(), ST->getAlign());
20328+
SDValue NewST = DAG.getStore(ST->getChain(), SDLoc(N), NewLD,
20329+
ST->getBasePtr(), ST->getMemOperand());
2033220330

2033320331
AddToWorklist(NewLD.getNode());
2033420332
AddToWorklist(NewST.getNode());
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
; NOTE: Assertions have been autogenerated by utils/update_mir_test_checks.py UTC_ARGS: --version 5
2+
; RUN: llc -mtriple=arm-none-eabi -stop-after=finalize-isel < %s | FileCheck %s
3+
4+
define void @test(ptr %vol_one, ptr %p_in, ptr %p_out, i32 %n) {
5+
; CHECK-LABEL: name: test
6+
; CHECK: bb.0.entry:
7+
; CHECK-NEXT: liveins: $r0, $r1, $r2
8+
; CHECK-NEXT: {{ $}}
9+
; CHECK-NEXT: [[COPY:%[0-9]+]]:gpr = COPY $r2
10+
; CHECK-NEXT: [[COPY1:%[0-9]+]]:gpr = COPY $r1
11+
; CHECK-NEXT: [[COPY2:%[0-9]+]]:gpr = COPY $r0
12+
; CHECK-NEXT: [[LDRi12_:%[0-9]+]]:gpr = LDRi12 [[COPY1]], 0, 14 /* CC::al */, $noreg :: (load (s32) from %ir.p_in)
13+
; CHECK-NEXT: STRi12 killed [[LDRi12_]], [[COPY2]], 0, 14 /* CC::al */, $noreg :: (volatile store (s32) into %ir.vol_one)
14+
; CHECK-NEXT: [[LDRi12_1:%[0-9]+]]:gpr = LDRi12 [[COPY2]], 4, 14 /* CC::al */, $noreg :: (volatile load (s32) from %ir.vol_two)
15+
; CHECK-NEXT: STRi12 killed [[LDRi12_1]], [[COPY]], 0, 14 /* CC::al */, $noreg :: (store (s32) into %ir.p_out)
16+
; CHECK-NEXT: MOVPCLR 14 /* CC::al */, $noreg
17+
entry:
18+
%vol_two = getelementptr inbounds i8, ptr %vol_one, i32 4
19+
%a = load float, ptr %p_in, align 4
20+
store volatile float %a, ptr %vol_one, align 4
21+
%b = load volatile float, ptr %vol_two, align 4
22+
store float %b, ptr %p_out, align 4
23+
ret void
24+
}

llvm/test/CodeGen/PowerPC/aix-cc-abi-mir.ll

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1442,8 +1442,8 @@ define void @caller_fpr_stack() {
14421442
; 32BIT-NEXT: renamable $r4 = LWZtoc @f14, $r2 :: (load (s32) from got)
14431443
; 32BIT-NEXT: renamable $f0 = LFD 0, killed renamable $r3 :: (dereferenceable load (s64) from @d15)
14441444
; 32BIT-NEXT: renamable $r5 = LWZtoc @f16, $r2 :: (load (s32) from got)
1445-
; 32BIT-NEXT: renamable $r3 = LWZ 0, killed renamable $r4 :: (load (s32) from @f14)
1446-
; 32BIT-NEXT: renamable $r4 = LWZ 0, killed renamable $r5 :: (load (s32) from @f16)
1445+
; 32BIT-NEXT: renamable $r3 = LWZ 0, killed renamable $r4 :: (dereferenceable load (s32) from @f14)
1446+
; 32BIT-NEXT: renamable $r4 = LWZ 0, killed renamable $r5 :: (dereferenceable load (s32) from @f16)
14471447
; 32BIT-NEXT: ADJCALLSTACKDOWN 144, 0, implicit-def dead $r1, implicit $r1
14481448
; 32BIT-NEXT: renamable $r5 = LI 0
14491449
; 32BIT-NEXT: renamable $r6 = LIS 16352
@@ -1532,9 +1532,9 @@ define void @caller_fpr_stack() {
15321532
; 64BIT-NEXT: renamable $x3 = LDtoc @f14, $x2 :: (load (s64) from got)
15331533
; 64BIT-NEXT: renamable $x4 = LDtoc @d15, $x2 :: (load (s64) from got)
15341534
; 64BIT-NEXT: renamable $x5 = LDtoc @f16, $x2 :: (load (s64) from got)
1535-
; 64BIT-NEXT: renamable $r3 = LWZ 0, killed renamable $x3 :: (load (s32) from @f14)
1536-
; 64BIT-NEXT: renamable $x4 = LD 0, killed renamable $x4 :: (load (s64) from @d15)
1537-
; 64BIT-NEXT: renamable $r5 = LWZ 0, killed renamable $x5 :: (load (s32) from @f16)
1535+
; 64BIT-NEXT: renamable $r3 = LWZ 0, killed renamable $x3 :: (dereferenceable load (s32) from @f14)
1536+
; 64BIT-NEXT: renamable $x4 = LD 0, killed renamable $x4 :: (dereferenceable load (s64) from @d15)
1537+
; 64BIT-NEXT: renamable $r5 = LWZ 0, killed renamable $x5 :: (dereferenceable load (s32) from @f16)
15381538
; 64BIT-NEXT: ADJCALLSTACKDOWN 176, 0, implicit-def dead $r1, implicit $r1
15391539
; 64BIT-NEXT: renamable $x6 = LDtocCPT %const.0, $x2 :: (load (s64) from got)
15401540
; 64BIT-NEXT: STW killed renamable $r5, 168, $x1 :: (store (s32))

0 commit comments

Comments
 (0)