llvm.org GIT mirror llvm / 3d5ea4c
[GlobalISel][AArch64] Select store of zero to WZR/XZR. These occur very frequently, and are quite trivial to catch. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@298862 91177308-0d34-0410-b5e6-96231b3b80d8 Ahmed Bougacha 3 years ago
2 changed file(s) with 67 addition(s) and 0 deletion(s). Raw diff Collapse all Expand all
774774 I.setDesc(TII.get(NewOpc));
775775
776776 I.addOperand(MachineOperand::CreateImm(0));
777
778 // If we're storing a 0, use WZR/XZR.
779 if (auto CVal = getConstantVRegVal(ValReg, MRI)) {
780 if (*CVal == 0 && Opcode == TargetOpcode::G_STORE) {
781 if (I.getOpcode() == AArch64::STRWui)
782 I.getOperand(0).setReg(AArch64::WZR);
783 else if (I.getOpcode() == AArch64::STRXui)
784 I.getOperand(0).setReg(AArch64::XZR);
785 }
786 }
787
777788 return constrainSelectedInstRegOperands(I, TII, TRI, RBI);
778789 }
779790
66 define void @store_s32_gpr(i32* %addr) { ret void }
77 define void @store_s16_gpr(i16* %addr) { ret void }
88 define void @store_s8_gpr(i8* %addr) { ret void }
9
10 define void @store_zero_s64_gpr(i64* %addr) { ret void }
11 define void @store_zero_s32_gpr(i32* %addr) { ret void }
12
913 define void @store_s64_fpr(i64* %addr) { ret void }
1014 define void @store_s32_fpr(i32* %addr) { ret void }
1115 ...
119123 ...
120124
121125 ---
126 # CHECK-LABEL: name: store_zero_s64_gpr
127 name: store_zero_s64_gpr
128 legalized: true
129 regBankSelected: true
130
131 # CHECK: registers:
132 # CHECK-NEXT: - { id: 0, class: gpr64sp }
133 # CHECK-NEXT: - { id: 1, class: gpr }
134 registers:
135 - { id: 0, class: gpr }
136 - { id: 1, class: gpr }
137
138 # CHECK: body:
139 # CHECK: %0 = COPY %x0
140 # CHECK: STRXui %xzr, %0, 0 :: (store 8 into %ir.addr)
141 body: |
142 bb.0:
143 liveins: %x0, %x1
144
145 %0(p0) = COPY %x0
146 %1(s64) = G_CONSTANT i64 0
147 G_STORE %1, %0 :: (store 8 into %ir.addr)
148
149 ...
150
151 ---
152 # CHECK-LABEL: name: store_zero_s32_gpr
153 name: store_zero_s32_gpr
154 legalized: true
155 regBankSelected: true
156
157 # CHECK: registers:
158 # CHECK-NEXT: - { id: 0, class: gpr64sp }
159 # CHECK-NEXT: - { id: 1, class: gpr }
160 registers:
161 - { id: 0, class: gpr }
162 - { id: 1, class: gpr }
163
164 # CHECK: body:
165 # CHECK: %0 = COPY %x0
166 # CHECK: STRWui %wzr, %0, 0 :: (store 4 into %ir.addr)
167 body: |
168 bb.0:
169 liveins: %x0
170
171 %0(p0) = COPY %x0
172 %1(s32) = G_CONSTANT i32 0
173 G_STORE %1, %0 :: (store 4 into %ir.addr)
174
175 ...
176
177 ---
122178 # CHECK-LABEL: name: store_s64_fpr
123179 name: store_s64_fpr
124180 legalized: true