1*9880d681SAndroid Build Coastguard Worker//===- README.txt - Notes for improving PowerPC-specific code gen ---------===// 2*9880d681SAndroid Build Coastguard Worker 3*9880d681SAndroid Build Coastguard WorkerTODO: 4*9880d681SAndroid Build Coastguard Worker* lmw/stmw pass a la arm load store optimizer for prolog/epilog 5*9880d681SAndroid Build Coastguard Worker 6*9880d681SAndroid Build Coastguard Worker===-------------------------------------------------------------------------=== 7*9880d681SAndroid Build Coastguard Worker 8*9880d681SAndroid Build Coastguard WorkerThis code: 9*9880d681SAndroid Build Coastguard Worker 10*9880d681SAndroid Build Coastguard Workerunsigned add32carry(unsigned sum, unsigned x) { 11*9880d681SAndroid Build Coastguard Worker unsigned z = sum + x; 12*9880d681SAndroid Build Coastguard Worker if (sum + x < x) 13*9880d681SAndroid Build Coastguard Worker z++; 14*9880d681SAndroid Build Coastguard Worker return z; 15*9880d681SAndroid Build Coastguard Worker} 16*9880d681SAndroid Build Coastguard Worker 17*9880d681SAndroid Build Coastguard WorkerShould compile to something like: 18*9880d681SAndroid Build Coastguard Worker 19*9880d681SAndroid Build Coastguard Worker addc r3,r3,r4 20*9880d681SAndroid Build Coastguard Worker addze r3,r3 21*9880d681SAndroid Build Coastguard Worker 22*9880d681SAndroid Build Coastguard Workerinstead we get: 23*9880d681SAndroid Build Coastguard Worker 24*9880d681SAndroid Build Coastguard Worker add r3, r4, r3 25*9880d681SAndroid Build Coastguard Worker cmplw cr7, r3, r4 26*9880d681SAndroid Build Coastguard Worker mfcr r4 ; 1 27*9880d681SAndroid Build Coastguard Worker rlwinm r4, r4, 29, 31, 31 28*9880d681SAndroid Build Coastguard Worker add r3, r3, r4 29*9880d681SAndroid Build Coastguard Worker 30*9880d681SAndroid Build Coastguard WorkerIck. 31*9880d681SAndroid Build Coastguard Worker 32*9880d681SAndroid Build Coastguard Worker===-------------------------------------------------------------------------=== 33*9880d681SAndroid Build Coastguard Worker 34*9880d681SAndroid Build Coastguard WorkerWe compile the hottest inner loop of viterbi to: 35*9880d681SAndroid Build Coastguard Worker 36*9880d681SAndroid Build Coastguard Worker li r6, 0 37*9880d681SAndroid Build Coastguard Worker b LBB1_84 ;bb432.i 38*9880d681SAndroid Build Coastguard WorkerLBB1_83: ;bb420.i 39*9880d681SAndroid Build Coastguard Worker lbzx r8, r5, r7 40*9880d681SAndroid Build Coastguard Worker addi r6, r7, 1 41*9880d681SAndroid Build Coastguard Worker stbx r8, r4, r7 42*9880d681SAndroid Build Coastguard WorkerLBB1_84: ;bb432.i 43*9880d681SAndroid Build Coastguard Worker mr r7, r6 44*9880d681SAndroid Build Coastguard Worker cmplwi cr0, r7, 143 45*9880d681SAndroid Build Coastguard Worker bne cr0, LBB1_83 ;bb420.i 46*9880d681SAndroid Build Coastguard Worker 47*9880d681SAndroid Build Coastguard WorkerThe CBE manages to produce: 48*9880d681SAndroid Build Coastguard Worker 49*9880d681SAndroid Build Coastguard Worker li r0, 143 50*9880d681SAndroid Build Coastguard Worker mtctr r0 51*9880d681SAndroid Build Coastguard Workerloop: 52*9880d681SAndroid Build Coastguard Worker lbzx r2, r2, r11 53*9880d681SAndroid Build Coastguard Worker stbx r0, r2, r9 54*9880d681SAndroid Build Coastguard Worker addi r2, r2, 1 55*9880d681SAndroid Build Coastguard Worker bdz later 56*9880d681SAndroid Build Coastguard Worker b loop 57*9880d681SAndroid Build Coastguard Worker 58*9880d681SAndroid Build Coastguard WorkerThis could be much better (bdnz instead of bdz) but it still beats us. If we 59*9880d681SAndroid Build Coastguard Workerproduced this with bdnz, the loop would be a single dispatch group. 60*9880d681SAndroid Build Coastguard Worker 61*9880d681SAndroid Build Coastguard Worker===-------------------------------------------------------------------------=== 62*9880d681SAndroid Build Coastguard Worker 63*9880d681SAndroid Build Coastguard WorkerLump the constant pool for each function into ONE pic object, and reference 64*9880d681SAndroid Build Coastguard Workerpieces of it as offsets from the start. For functions like this (contrived 65*9880d681SAndroid Build Coastguard Workerto have lots of constants obviously): 66*9880d681SAndroid Build Coastguard Worker 67*9880d681SAndroid Build Coastguard Workerdouble X(double Y) { return (Y*1.23 + 4.512)*2.34 + 14.38; } 68*9880d681SAndroid Build Coastguard Worker 69*9880d681SAndroid Build Coastguard WorkerWe generate: 70*9880d681SAndroid Build Coastguard Worker 71*9880d681SAndroid Build Coastguard Worker_X: 72*9880d681SAndroid Build Coastguard Worker lis r2, ha16(.CPI_X_0) 73*9880d681SAndroid Build Coastguard Worker lfd f0, lo16(.CPI_X_0)(r2) 74*9880d681SAndroid Build Coastguard Worker lis r2, ha16(.CPI_X_1) 75*9880d681SAndroid Build Coastguard Worker lfd f2, lo16(.CPI_X_1)(r2) 76*9880d681SAndroid Build Coastguard Worker fmadd f0, f1, f0, f2 77*9880d681SAndroid Build Coastguard Worker lis r2, ha16(.CPI_X_2) 78*9880d681SAndroid Build Coastguard Worker lfd f1, lo16(.CPI_X_2)(r2) 79*9880d681SAndroid Build Coastguard Worker lis r2, ha16(.CPI_X_3) 80*9880d681SAndroid Build Coastguard Worker lfd f2, lo16(.CPI_X_3)(r2) 81*9880d681SAndroid Build Coastguard Worker fmadd f1, f0, f1, f2 82*9880d681SAndroid Build Coastguard Worker blr 83*9880d681SAndroid Build Coastguard Worker 84*9880d681SAndroid Build Coastguard WorkerIt would be better to materialize .CPI_X into a register, then use immediates 85*9880d681SAndroid Build Coastguard Workeroff of the register to avoid the lis's. This is even more important in PIC 86*9880d681SAndroid Build Coastguard Workermode. 87*9880d681SAndroid Build Coastguard Worker 88*9880d681SAndroid Build Coastguard WorkerNote that this (and the static variable version) is discussed here for GCC: 89*9880d681SAndroid Build Coastguard Workerhttp://gcc.gnu.org/ml/gcc-patches/2006-02/msg00133.html 90*9880d681SAndroid Build Coastguard Worker 91*9880d681SAndroid Build Coastguard WorkerHere's another example (the sgn function): 92*9880d681SAndroid Build Coastguard Workerdouble testf(double a) { 93*9880d681SAndroid Build Coastguard Worker return a == 0.0 ? 0.0 : (a > 0.0 ? 1.0 : -1.0); 94*9880d681SAndroid Build Coastguard Worker} 95*9880d681SAndroid Build Coastguard Worker 96*9880d681SAndroid Build Coastguard Workerit produces a BB like this: 97*9880d681SAndroid Build Coastguard WorkerLBB1_1: ; cond_true 98*9880d681SAndroid Build Coastguard Worker lis r2, ha16(LCPI1_0) 99*9880d681SAndroid Build Coastguard Worker lfs f0, lo16(LCPI1_0)(r2) 100*9880d681SAndroid Build Coastguard Worker lis r2, ha16(LCPI1_1) 101*9880d681SAndroid Build Coastguard Worker lis r3, ha16(LCPI1_2) 102*9880d681SAndroid Build Coastguard Worker lfs f2, lo16(LCPI1_2)(r3) 103*9880d681SAndroid Build Coastguard Worker lfs f3, lo16(LCPI1_1)(r2) 104*9880d681SAndroid Build Coastguard Worker fsub f0, f0, f1 105*9880d681SAndroid Build Coastguard Worker fsel f1, f0, f2, f3 106*9880d681SAndroid Build Coastguard Worker blr 107*9880d681SAndroid Build Coastguard Worker 108*9880d681SAndroid Build Coastguard Worker===-------------------------------------------------------------------------=== 109*9880d681SAndroid Build Coastguard Worker 110*9880d681SAndroid Build Coastguard WorkerPIC Code Gen IPO optimization: 111*9880d681SAndroid Build Coastguard Worker 112*9880d681SAndroid Build Coastguard WorkerSquish small scalar globals together into a single global struct, allowing the 113*9880d681SAndroid Build Coastguard Workeraddress of the struct to be CSE'd, avoiding PIC accesses (also reduces the size 114*9880d681SAndroid Build Coastguard Workerof the GOT on targets with one). 115*9880d681SAndroid Build Coastguard Worker 116*9880d681SAndroid Build Coastguard WorkerNote that this is discussed here for GCC: 117*9880d681SAndroid Build Coastguard Workerhttp://gcc.gnu.org/ml/gcc-patches/2006-02/msg00133.html 118*9880d681SAndroid Build Coastguard Worker 119*9880d681SAndroid Build Coastguard Worker===-------------------------------------------------------------------------=== 120*9880d681SAndroid Build Coastguard Worker 121*9880d681SAndroid Build Coastguard WorkerDarwin Stub removal: 122*9880d681SAndroid Build Coastguard Worker 123*9880d681SAndroid Build Coastguard WorkerWe still generate calls to foo$stub, and stubs, on Darwin. This is not 124*9880d681SAndroid Build Coastguard Workernecessary when building with the Leopard (10.5) or later linker, as stubs are 125*9880d681SAndroid Build Coastguard Workergenerated by ld when necessary. Parameterizing this based on the deployment 126*9880d681SAndroid Build Coastguard Workertarget (-mmacosx-version-min) is probably enough. x86-32 does this right, see 127*9880d681SAndroid Build Coastguard Workerits logic. 128*9880d681SAndroid Build Coastguard Worker 129*9880d681SAndroid Build Coastguard Worker===-------------------------------------------------------------------------=== 130*9880d681SAndroid Build Coastguard Worker 131*9880d681SAndroid Build Coastguard WorkerDarwin Stub LICM optimization: 132*9880d681SAndroid Build Coastguard Worker 133*9880d681SAndroid Build Coastguard WorkerLoops like this: 134*9880d681SAndroid Build Coastguard Worker 135*9880d681SAndroid Build Coastguard Worker for (...) bar(); 136*9880d681SAndroid Build Coastguard Worker 137*9880d681SAndroid Build Coastguard WorkerHave to go through an indirect stub if bar is external or linkonce. It would 138*9880d681SAndroid Build Coastguard Workerbe better to compile it as: 139*9880d681SAndroid Build Coastguard Worker 140*9880d681SAndroid Build Coastguard Worker fp = &bar; 141*9880d681SAndroid Build Coastguard Worker for (...) fp(); 142*9880d681SAndroid Build Coastguard Worker 143*9880d681SAndroid Build Coastguard Workerwhich only computes the address of bar once (instead of each time through the 144*9880d681SAndroid Build Coastguard Workerstub). This is Darwin specific and would have to be done in the code generator. 145*9880d681SAndroid Build Coastguard WorkerProbably not a win on x86. 146*9880d681SAndroid Build Coastguard Worker 147*9880d681SAndroid Build Coastguard Worker===-------------------------------------------------------------------------=== 148*9880d681SAndroid Build Coastguard Worker 149*9880d681SAndroid Build Coastguard WorkerSimple IPO for argument passing, change: 150*9880d681SAndroid Build Coastguard Worker void foo(int X, double Y, int Z) -> void foo(int X, int Z, double Y) 151*9880d681SAndroid Build Coastguard Worker 152*9880d681SAndroid Build Coastguard Workerthe Darwin ABI specifies that any integer arguments in the first 32 bytes worth 153*9880d681SAndroid Build Coastguard Workerof arguments get assigned to r3 through r10. That is, if you have a function 154*9880d681SAndroid Build Coastguard Workerfoo(int, double, int) you get r3, f1, r6, since the 64 bit double ate up the 155*9880d681SAndroid Build Coastguard Workerargument bytes for r4 and r5. The trick then would be to shuffle the argument 156*9880d681SAndroid Build Coastguard Workerorder for functions we can internalize so that the maximum number of 157*9880d681SAndroid Build Coastguard Workerintegers/pointers get passed in regs before you see any of the fp arguments. 158*9880d681SAndroid Build Coastguard Worker 159*9880d681SAndroid Build Coastguard WorkerInstead of implementing this, it would actually probably be easier to just 160*9880d681SAndroid Build Coastguard Workerimplement a PPC fastcc, where we could do whatever we wanted to the CC, 161*9880d681SAndroid Build Coastguard Workerincluding having this work sanely. 162*9880d681SAndroid Build Coastguard Worker 163*9880d681SAndroid Build Coastguard Worker===-------------------------------------------------------------------------=== 164*9880d681SAndroid Build Coastguard Worker 165*9880d681SAndroid Build Coastguard WorkerFix Darwin FP-In-Integer Registers ABI 166*9880d681SAndroid Build Coastguard Worker 167*9880d681SAndroid Build Coastguard WorkerDarwin passes doubles in structures in integer registers, which is very very 168*9880d681SAndroid Build Coastguard Workerbad. Add something like a BITCAST to LLVM, then do an i-p transformation that 169*9880d681SAndroid Build Coastguard Workerpercolates these things out of functions. 170*9880d681SAndroid Build Coastguard Worker 171*9880d681SAndroid Build Coastguard WorkerCheck out how horrible this is: 172*9880d681SAndroid Build Coastguard Workerhttp://gcc.gnu.org/ml/gcc/2005-10/msg01036.html 173*9880d681SAndroid Build Coastguard Worker 174*9880d681SAndroid Build Coastguard WorkerThis is an extension of "interprocedural CC unmunging" that can't be done with 175*9880d681SAndroid Build Coastguard Workerjust fastcc. 176*9880d681SAndroid Build Coastguard Worker 177*9880d681SAndroid Build Coastguard Worker===-------------------------------------------------------------------------=== 178*9880d681SAndroid Build Coastguard Worker 179*9880d681SAndroid Build Coastguard WorkerFold add and sub with constant into non-extern, non-weak addresses so this: 180*9880d681SAndroid Build Coastguard Worker 181*9880d681SAndroid Build Coastguard Workerstatic int a; 182*9880d681SAndroid Build Coastguard Workervoid bar(int b) { a = b; } 183*9880d681SAndroid Build Coastguard Workervoid foo(unsigned char *c) { 184*9880d681SAndroid Build Coastguard Worker *c = a; 185*9880d681SAndroid Build Coastguard Worker} 186*9880d681SAndroid Build Coastguard Worker 187*9880d681SAndroid Build Coastguard WorkerSo that 188*9880d681SAndroid Build Coastguard Worker 189*9880d681SAndroid Build Coastguard Worker_foo: 190*9880d681SAndroid Build Coastguard Worker lis r2, ha16(_a) 191*9880d681SAndroid Build Coastguard Worker la r2, lo16(_a)(r2) 192*9880d681SAndroid Build Coastguard Worker lbz r2, 3(r2) 193*9880d681SAndroid Build Coastguard Worker stb r2, 0(r3) 194*9880d681SAndroid Build Coastguard Worker blr 195*9880d681SAndroid Build Coastguard Worker 196*9880d681SAndroid Build Coastguard WorkerBecomes 197*9880d681SAndroid Build Coastguard Worker 198*9880d681SAndroid Build Coastguard Worker_foo: 199*9880d681SAndroid Build Coastguard Worker lis r2, ha16(_a+3) 200*9880d681SAndroid Build Coastguard Worker lbz r2, lo16(_a+3)(r2) 201*9880d681SAndroid Build Coastguard Worker stb r2, 0(r3) 202*9880d681SAndroid Build Coastguard Worker blr 203*9880d681SAndroid Build Coastguard Worker 204*9880d681SAndroid Build Coastguard Worker===-------------------------------------------------------------------------=== 205*9880d681SAndroid Build Coastguard Worker 206*9880d681SAndroid Build Coastguard WorkerWe should compile these two functions to the same thing: 207*9880d681SAndroid Build Coastguard Worker 208*9880d681SAndroid Build Coastguard Worker#include <stdlib.h> 209*9880d681SAndroid Build Coastguard Workervoid f(int a, int b, int *P) { 210*9880d681SAndroid Build Coastguard Worker *P = (a-b)>=0?(a-b):(b-a); 211*9880d681SAndroid Build Coastguard Worker} 212*9880d681SAndroid Build Coastguard Workervoid g(int a, int b, int *P) { 213*9880d681SAndroid Build Coastguard Worker *P = abs(a-b); 214*9880d681SAndroid Build Coastguard Worker} 215*9880d681SAndroid Build Coastguard Worker 216*9880d681SAndroid Build Coastguard WorkerFurther, they should compile to something better than: 217*9880d681SAndroid Build Coastguard Worker 218*9880d681SAndroid Build Coastguard Worker_g: 219*9880d681SAndroid Build Coastguard Worker subf r2, r4, r3 220*9880d681SAndroid Build Coastguard Worker subfic r3, r2, 0 221*9880d681SAndroid Build Coastguard Worker cmpwi cr0, r2, -1 222*9880d681SAndroid Build Coastguard Worker bgt cr0, LBB2_2 ; entry 223*9880d681SAndroid Build Coastguard WorkerLBB2_1: ; entry 224*9880d681SAndroid Build Coastguard Worker mr r2, r3 225*9880d681SAndroid Build Coastguard WorkerLBB2_2: ; entry 226*9880d681SAndroid Build Coastguard Worker stw r2, 0(r5) 227*9880d681SAndroid Build Coastguard Worker blr 228*9880d681SAndroid Build Coastguard Worker 229*9880d681SAndroid Build Coastguard WorkerGCC produces: 230*9880d681SAndroid Build Coastguard Worker 231*9880d681SAndroid Build Coastguard Worker_g: 232*9880d681SAndroid Build Coastguard Worker subf r4,r4,r3 233*9880d681SAndroid Build Coastguard Worker srawi r2,r4,31 234*9880d681SAndroid Build Coastguard Worker xor r0,r2,r4 235*9880d681SAndroid Build Coastguard Worker subf r0,r2,r0 236*9880d681SAndroid Build Coastguard Worker stw r0,0(r5) 237*9880d681SAndroid Build Coastguard Worker blr 238*9880d681SAndroid Build Coastguard Worker 239*9880d681SAndroid Build Coastguard Worker... which is much nicer. 240*9880d681SAndroid Build Coastguard Worker 241*9880d681SAndroid Build Coastguard WorkerThis theoretically may help improve twolf slightly (used in dimbox.c:142?). 242*9880d681SAndroid Build Coastguard Worker 243*9880d681SAndroid Build Coastguard Worker===-------------------------------------------------------------------------=== 244*9880d681SAndroid Build Coastguard Worker 245*9880d681SAndroid Build Coastguard WorkerPR5945: This: 246*9880d681SAndroid Build Coastguard Workerdefine i32 @clamp0g(i32 %a) { 247*9880d681SAndroid Build Coastguard Workerentry: 248*9880d681SAndroid Build Coastguard Worker %cmp = icmp slt i32 %a, 0 249*9880d681SAndroid Build Coastguard Worker %sel = select i1 %cmp, i32 0, i32 %a 250*9880d681SAndroid Build Coastguard Worker ret i32 %sel 251*9880d681SAndroid Build Coastguard Worker} 252*9880d681SAndroid Build Coastguard Worker 253*9880d681SAndroid Build Coastguard WorkerIs compile to this with the PowerPC (32-bit) backend: 254*9880d681SAndroid Build Coastguard Worker 255*9880d681SAndroid Build Coastguard Worker_clamp0g: 256*9880d681SAndroid Build Coastguard Worker cmpwi cr0, r3, 0 257*9880d681SAndroid Build Coastguard Worker li r2, 0 258*9880d681SAndroid Build Coastguard Worker blt cr0, LBB1_2 259*9880d681SAndroid Build Coastguard Worker; BB#1: ; %entry 260*9880d681SAndroid Build Coastguard Worker mr r2, r3 261*9880d681SAndroid Build Coastguard WorkerLBB1_2: ; %entry 262*9880d681SAndroid Build Coastguard Worker mr r3, r2 263*9880d681SAndroid Build Coastguard Worker blr 264*9880d681SAndroid Build Coastguard Worker 265*9880d681SAndroid Build Coastguard WorkerThis could be reduced to the much simpler: 266*9880d681SAndroid Build Coastguard Worker 267*9880d681SAndroid Build Coastguard Worker_clamp0g: 268*9880d681SAndroid Build Coastguard Worker srawi r2, r3, 31 269*9880d681SAndroid Build Coastguard Worker andc r3, r3, r2 270*9880d681SAndroid Build Coastguard Worker blr 271*9880d681SAndroid Build Coastguard Worker 272*9880d681SAndroid Build Coastguard Worker===-------------------------------------------------------------------------=== 273*9880d681SAndroid Build Coastguard Worker 274*9880d681SAndroid Build Coastguard Workerint foo(int N, int ***W, int **TK, int X) { 275*9880d681SAndroid Build Coastguard Worker int t, i; 276*9880d681SAndroid Build Coastguard Worker 277*9880d681SAndroid Build Coastguard Worker for (t = 0; t < N; ++t) 278*9880d681SAndroid Build Coastguard Worker for (i = 0; i < 4; ++i) 279*9880d681SAndroid Build Coastguard Worker W[t / X][i][t % X] = TK[i][t]; 280*9880d681SAndroid Build Coastguard Worker 281*9880d681SAndroid Build Coastguard Worker return 5; 282*9880d681SAndroid Build Coastguard Worker} 283*9880d681SAndroid Build Coastguard Worker 284*9880d681SAndroid Build Coastguard WorkerWe generate relatively atrocious code for this loop compared to gcc. 285*9880d681SAndroid Build Coastguard Worker 286*9880d681SAndroid Build Coastguard WorkerWe could also strength reduce the rem and the div: 287*9880d681SAndroid Build Coastguard Workerhttp://www.lcs.mit.edu/pubs/pdf/MIT-LCS-TM-600.pdf 288*9880d681SAndroid Build Coastguard Worker 289*9880d681SAndroid Build Coastguard Worker===-------------------------------------------------------------------------=== 290*9880d681SAndroid Build Coastguard Worker 291*9880d681SAndroid Build Coastguard WorkerWe generate ugly code for this: 292*9880d681SAndroid Build Coastguard Worker 293*9880d681SAndroid Build Coastguard Workervoid func(unsigned int *ret, float dx, float dy, float dz, float dw) { 294*9880d681SAndroid Build Coastguard Worker unsigned code = 0; 295*9880d681SAndroid Build Coastguard Worker if(dx < -dw) code |= 1; 296*9880d681SAndroid Build Coastguard Worker if(dx > dw) code |= 2; 297*9880d681SAndroid Build Coastguard Worker if(dy < -dw) code |= 4; 298*9880d681SAndroid Build Coastguard Worker if(dy > dw) code |= 8; 299*9880d681SAndroid Build Coastguard Worker if(dz < -dw) code |= 16; 300*9880d681SAndroid Build Coastguard Worker if(dz > dw) code |= 32; 301*9880d681SAndroid Build Coastguard Worker *ret = code; 302*9880d681SAndroid Build Coastguard Worker} 303*9880d681SAndroid Build Coastguard Worker 304*9880d681SAndroid Build Coastguard Worker===-------------------------------------------------------------------------=== 305*9880d681SAndroid Build Coastguard Worker 306*9880d681SAndroid Build Coastguard Worker%struct.B = type { i8, [3 x i8] } 307*9880d681SAndroid Build Coastguard Worker 308*9880d681SAndroid Build Coastguard Workerdefine void @bar(%struct.B* %b) { 309*9880d681SAndroid Build Coastguard Workerentry: 310*9880d681SAndroid Build Coastguard Worker %tmp = bitcast %struct.B* %b to i32* ; <uint*> [#uses=1] 311*9880d681SAndroid Build Coastguard Worker %tmp = load i32* %tmp ; <uint> [#uses=1] 312*9880d681SAndroid Build Coastguard Worker %tmp3 = bitcast %struct.B* %b to i32* ; <uint*> [#uses=1] 313*9880d681SAndroid Build Coastguard Worker %tmp4 = load i32* %tmp3 ; <uint> [#uses=1] 314*9880d681SAndroid Build Coastguard Worker %tmp8 = bitcast %struct.B* %b to i32* ; <uint*> [#uses=2] 315*9880d681SAndroid Build Coastguard Worker %tmp9 = load i32* %tmp8 ; <uint> [#uses=1] 316*9880d681SAndroid Build Coastguard Worker %tmp4.mask17 = shl i32 %tmp4, i8 1 ; <uint> [#uses=1] 317*9880d681SAndroid Build Coastguard Worker %tmp1415 = and i32 %tmp4.mask17, 2147483648 ; <uint> [#uses=1] 318*9880d681SAndroid Build Coastguard Worker %tmp.masked = and i32 %tmp, 2147483648 ; <uint> [#uses=1] 319*9880d681SAndroid Build Coastguard Worker %tmp11 = or i32 %tmp1415, %tmp.masked ; <uint> [#uses=1] 320*9880d681SAndroid Build Coastguard Worker %tmp12 = and i32 %tmp9, 2147483647 ; <uint> [#uses=1] 321*9880d681SAndroid Build Coastguard Worker %tmp13 = or i32 %tmp12, %tmp11 ; <uint> [#uses=1] 322*9880d681SAndroid Build Coastguard Worker store i32 %tmp13, i32* %tmp8 323*9880d681SAndroid Build Coastguard Worker ret void 324*9880d681SAndroid Build Coastguard Worker} 325*9880d681SAndroid Build Coastguard Worker 326*9880d681SAndroid Build Coastguard WorkerWe emit: 327*9880d681SAndroid Build Coastguard Worker 328*9880d681SAndroid Build Coastguard Worker_foo: 329*9880d681SAndroid Build Coastguard Worker lwz r2, 0(r3) 330*9880d681SAndroid Build Coastguard Worker slwi r4, r2, 1 331*9880d681SAndroid Build Coastguard Worker or r4, r4, r2 332*9880d681SAndroid Build Coastguard Worker rlwimi r2, r4, 0, 0, 0 333*9880d681SAndroid Build Coastguard Worker stw r2, 0(r3) 334*9880d681SAndroid Build Coastguard Worker blr 335*9880d681SAndroid Build Coastguard Worker 336*9880d681SAndroid Build Coastguard WorkerWe could collapse a bunch of those ORs and ANDs and generate the following 337*9880d681SAndroid Build Coastguard Workerequivalent code: 338*9880d681SAndroid Build Coastguard Worker 339*9880d681SAndroid Build Coastguard Worker_foo: 340*9880d681SAndroid Build Coastguard Worker lwz r2, 0(r3) 341*9880d681SAndroid Build Coastguard Worker rlwinm r4, r2, 1, 0, 0 342*9880d681SAndroid Build Coastguard Worker or r2, r2, r4 343*9880d681SAndroid Build Coastguard Worker stw r2, 0(r3) 344*9880d681SAndroid Build Coastguard Worker blr 345*9880d681SAndroid Build Coastguard Worker 346*9880d681SAndroid Build Coastguard Worker===-------------------------------------------------------------------------=== 347*9880d681SAndroid Build Coastguard Worker 348*9880d681SAndroid Build Coastguard WorkerConsider a function like this: 349*9880d681SAndroid Build Coastguard Worker 350*9880d681SAndroid Build Coastguard Workerfloat foo(float X) { return X + 1234.4123f; } 351*9880d681SAndroid Build Coastguard Worker 352*9880d681SAndroid Build Coastguard WorkerThe FP constant ends up in the constant pool, so we need to get the LR register. 353*9880d681SAndroid Build Coastguard Worker This ends up producing code like this: 354*9880d681SAndroid Build Coastguard Worker 355*9880d681SAndroid Build Coastguard Worker_foo: 356*9880d681SAndroid Build Coastguard Worker.LBB_foo_0: ; entry 357*9880d681SAndroid Build Coastguard Worker mflr r11 358*9880d681SAndroid Build Coastguard Worker*** stw r11, 8(r1) 359*9880d681SAndroid Build Coastguard Worker bl "L00000$pb" 360*9880d681SAndroid Build Coastguard Worker"L00000$pb": 361*9880d681SAndroid Build Coastguard Worker mflr r2 362*9880d681SAndroid Build Coastguard Worker addis r2, r2, ha16(.CPI_foo_0-"L00000$pb") 363*9880d681SAndroid Build Coastguard Worker lfs f0, lo16(.CPI_foo_0-"L00000$pb")(r2) 364*9880d681SAndroid Build Coastguard Worker fadds f1, f1, f0 365*9880d681SAndroid Build Coastguard Worker*** lwz r11, 8(r1) 366*9880d681SAndroid Build Coastguard Worker mtlr r11 367*9880d681SAndroid Build Coastguard Worker blr 368*9880d681SAndroid Build Coastguard Worker 369*9880d681SAndroid Build Coastguard WorkerThis is functional, but there is no reason to spill the LR register all the way 370*9880d681SAndroid Build Coastguard Workerto the stack (the two marked instrs): spilling it to a GPR is quite enough. 371*9880d681SAndroid Build Coastguard Worker 372*9880d681SAndroid Build Coastguard WorkerImplementing this will require some codegen improvements. Nate writes: 373*9880d681SAndroid Build Coastguard Worker 374*9880d681SAndroid Build Coastguard Worker"So basically what we need to support the "no stack frame save and restore" is a 375*9880d681SAndroid Build Coastguard Workergeneralization of the LR optimization to "callee-save regs". 376*9880d681SAndroid Build Coastguard Worker 377*9880d681SAndroid Build Coastguard WorkerCurrently, we have LR marked as a callee-save reg. The register allocator sees 378*9880d681SAndroid Build Coastguard Workerthat it's callee save, and spills it directly to the stack. 379*9880d681SAndroid Build Coastguard Worker 380*9880d681SAndroid Build Coastguard WorkerIdeally, something like this would happen: 381*9880d681SAndroid Build Coastguard Worker 382*9880d681SAndroid Build Coastguard WorkerLR would be in a separate register class from the GPRs. The class of LR would be 383*9880d681SAndroid Build Coastguard Workermarked "unspillable". When the register allocator came across an unspillable 384*9880d681SAndroid Build Coastguard Workerreg, it would ask "what is the best class to copy this into that I *can* spill" 385*9880d681SAndroid Build Coastguard WorkerIf it gets a class back, which it will in this case (the gprs), it grabs a free 386*9880d681SAndroid Build Coastguard Workerregister of that class. If it is then later necessary to spill that reg, so be 387*9880d681SAndroid Build Coastguard Workerit. 388*9880d681SAndroid Build Coastguard Worker 389*9880d681SAndroid Build Coastguard Worker===-------------------------------------------------------------------------=== 390*9880d681SAndroid Build Coastguard Worker 391*9880d681SAndroid Build Coastguard WorkerWe compile this: 392*9880d681SAndroid Build Coastguard Workerint test(_Bool X) { 393*9880d681SAndroid Build Coastguard Worker return X ? 524288 : 0; 394*9880d681SAndroid Build Coastguard Worker} 395*9880d681SAndroid Build Coastguard Worker 396*9880d681SAndroid Build Coastguard Workerto: 397*9880d681SAndroid Build Coastguard Worker_test: 398*9880d681SAndroid Build Coastguard Worker cmplwi cr0, r3, 0 399*9880d681SAndroid Build Coastguard Worker lis r2, 8 400*9880d681SAndroid Build Coastguard Worker li r3, 0 401*9880d681SAndroid Build Coastguard Worker beq cr0, LBB1_2 ;entry 402*9880d681SAndroid Build Coastguard WorkerLBB1_1: ;entry 403*9880d681SAndroid Build Coastguard Worker mr r3, r2 404*9880d681SAndroid Build Coastguard WorkerLBB1_2: ;entry 405*9880d681SAndroid Build Coastguard Worker blr 406*9880d681SAndroid Build Coastguard Worker 407*9880d681SAndroid Build Coastguard Workerinstead of: 408*9880d681SAndroid Build Coastguard Worker_test: 409*9880d681SAndroid Build Coastguard Worker addic r2,r3,-1 410*9880d681SAndroid Build Coastguard Worker subfe r0,r2,r3 411*9880d681SAndroid Build Coastguard Worker slwi r3,r0,19 412*9880d681SAndroid Build Coastguard Worker blr 413*9880d681SAndroid Build Coastguard Worker 414*9880d681SAndroid Build Coastguard WorkerThis sort of thing occurs a lot due to globalopt. 415*9880d681SAndroid Build Coastguard Worker 416*9880d681SAndroid Build Coastguard Worker===-------------------------------------------------------------------------=== 417*9880d681SAndroid Build Coastguard Worker 418*9880d681SAndroid Build Coastguard WorkerWe compile: 419*9880d681SAndroid Build Coastguard Worker 420*9880d681SAndroid Build Coastguard Workerdefine i32 @bar(i32 %x) nounwind readnone ssp { 421*9880d681SAndroid Build Coastguard Workerentry: 422*9880d681SAndroid Build Coastguard Worker %0 = icmp eq i32 %x, 0 ; <i1> [#uses=1] 423*9880d681SAndroid Build Coastguard Worker %neg = sext i1 %0 to i32 ; <i32> [#uses=1] 424*9880d681SAndroid Build Coastguard Worker ret i32 %neg 425*9880d681SAndroid Build Coastguard Worker} 426*9880d681SAndroid Build Coastguard Worker 427*9880d681SAndroid Build Coastguard Workerto: 428*9880d681SAndroid Build Coastguard Worker 429*9880d681SAndroid Build Coastguard Worker_bar: 430*9880d681SAndroid Build Coastguard Worker cntlzw r2, r3 431*9880d681SAndroid Build Coastguard Worker slwi r2, r2, 26 432*9880d681SAndroid Build Coastguard Worker srawi r3, r2, 31 433*9880d681SAndroid Build Coastguard Worker blr 434*9880d681SAndroid Build Coastguard Worker 435*9880d681SAndroid Build Coastguard Workerit would be better to produce: 436*9880d681SAndroid Build Coastguard Worker 437*9880d681SAndroid Build Coastguard Worker_bar: 438*9880d681SAndroid Build Coastguard Worker addic r3,r3,-1 439*9880d681SAndroid Build Coastguard Worker subfe r3,r3,r3 440*9880d681SAndroid Build Coastguard Worker blr 441*9880d681SAndroid Build Coastguard Worker 442*9880d681SAndroid Build Coastguard Worker===-------------------------------------------------------------------------=== 443*9880d681SAndroid Build Coastguard Worker 444*9880d681SAndroid Build Coastguard WorkerWe generate horrible ppc code for this: 445*9880d681SAndroid Build Coastguard Worker 446*9880d681SAndroid Build Coastguard Worker#define N 2000000 447*9880d681SAndroid Build Coastguard Workerdouble a[N],c[N]; 448*9880d681SAndroid Build Coastguard Workervoid simpleloop() { 449*9880d681SAndroid Build Coastguard Worker int j; 450*9880d681SAndroid Build Coastguard Worker for (j=0; j<N; j++) 451*9880d681SAndroid Build Coastguard Worker c[j] = a[j]; 452*9880d681SAndroid Build Coastguard Worker} 453*9880d681SAndroid Build Coastguard Worker 454*9880d681SAndroid Build Coastguard WorkerLBB1_1: ;bb 455*9880d681SAndroid Build Coastguard Worker lfdx f0, r3, r4 456*9880d681SAndroid Build Coastguard Worker addi r5, r5, 1 ;; Extra IV for the exit value compare. 457*9880d681SAndroid Build Coastguard Worker stfdx f0, r2, r4 458*9880d681SAndroid Build Coastguard Worker addi r4, r4, 8 459*9880d681SAndroid Build Coastguard Worker 460*9880d681SAndroid Build Coastguard Worker xoris r6, r5, 30 ;; This is due to a large immediate. 461*9880d681SAndroid Build Coastguard Worker cmplwi cr0, r6, 33920 462*9880d681SAndroid Build Coastguard Worker bne cr0, LBB1_1 463*9880d681SAndroid Build Coastguard Worker 464*9880d681SAndroid Build Coastguard Worker//===---------------------------------------------------------------------===// 465*9880d681SAndroid Build Coastguard Worker 466*9880d681SAndroid Build Coastguard WorkerThis: 467*9880d681SAndroid Build Coastguard Worker #include <algorithm> 468*9880d681SAndroid Build Coastguard Worker inline std::pair<unsigned, bool> full_add(unsigned a, unsigned b) 469*9880d681SAndroid Build Coastguard Worker { return std::make_pair(a + b, a + b < a); } 470*9880d681SAndroid Build Coastguard Worker bool no_overflow(unsigned a, unsigned b) 471*9880d681SAndroid Build Coastguard Worker { return !full_add(a, b).second; } 472*9880d681SAndroid Build Coastguard Worker 473*9880d681SAndroid Build Coastguard WorkerShould compile to: 474*9880d681SAndroid Build Coastguard Worker 475*9880d681SAndroid Build Coastguard Worker__Z11no_overflowjj: 476*9880d681SAndroid Build Coastguard Worker add r4,r3,r4 477*9880d681SAndroid Build Coastguard Worker subfc r3,r3,r4 478*9880d681SAndroid Build Coastguard Worker li r3,0 479*9880d681SAndroid Build Coastguard Worker adde r3,r3,r3 480*9880d681SAndroid Build Coastguard Worker blr 481*9880d681SAndroid Build Coastguard Worker 482*9880d681SAndroid Build Coastguard Worker(or better) not: 483*9880d681SAndroid Build Coastguard Worker 484*9880d681SAndroid Build Coastguard Worker__Z11no_overflowjj: 485*9880d681SAndroid Build Coastguard Worker add r2, r4, r3 486*9880d681SAndroid Build Coastguard Worker cmplw cr7, r2, r3 487*9880d681SAndroid Build Coastguard Worker mfcr r2 488*9880d681SAndroid Build Coastguard Worker rlwinm r2, r2, 29, 31, 31 489*9880d681SAndroid Build Coastguard Worker xori r3, r2, 1 490*9880d681SAndroid Build Coastguard Worker blr 491*9880d681SAndroid Build Coastguard Worker 492*9880d681SAndroid Build Coastguard Worker//===---------------------------------------------------------------------===// 493*9880d681SAndroid Build Coastguard Worker 494*9880d681SAndroid Build Coastguard WorkerWe compile some FP comparisons into an mfcr with two rlwinms and an or. For 495*9880d681SAndroid Build Coastguard Workerexample: 496*9880d681SAndroid Build Coastguard Worker#include <math.h> 497*9880d681SAndroid Build Coastguard Workerint test(double x, double y) { return islessequal(x, y);} 498*9880d681SAndroid Build Coastguard Workerint test2(double x, double y) { return islessgreater(x, y);} 499*9880d681SAndroid Build Coastguard Workerint test3(double x, double y) { return !islessequal(x, y);} 500*9880d681SAndroid Build Coastguard Worker 501*9880d681SAndroid Build Coastguard WorkerCompiles into (all three are similar, but the bits differ): 502*9880d681SAndroid Build Coastguard Worker 503*9880d681SAndroid Build Coastguard Worker_test: 504*9880d681SAndroid Build Coastguard Worker fcmpu cr7, f1, f2 505*9880d681SAndroid Build Coastguard Worker mfcr r2 506*9880d681SAndroid Build Coastguard Worker rlwinm r3, r2, 29, 31, 31 507*9880d681SAndroid Build Coastguard Worker rlwinm r2, r2, 31, 31, 31 508*9880d681SAndroid Build Coastguard Worker or r3, r2, r3 509*9880d681SAndroid Build Coastguard Worker blr 510*9880d681SAndroid Build Coastguard Worker 511*9880d681SAndroid Build Coastguard WorkerGCC compiles this into: 512*9880d681SAndroid Build Coastguard Worker 513*9880d681SAndroid Build Coastguard Worker _test: 514*9880d681SAndroid Build Coastguard Worker fcmpu cr7,f1,f2 515*9880d681SAndroid Build Coastguard Worker cror 30,28,30 516*9880d681SAndroid Build Coastguard Worker mfcr r3 517*9880d681SAndroid Build Coastguard Worker rlwinm r3,r3,31,1 518*9880d681SAndroid Build Coastguard Worker blr 519*9880d681SAndroid Build Coastguard Worker 520*9880d681SAndroid Build Coastguard Workerwhich is more efficient and can use mfocr. See PR642 for some more context. 521*9880d681SAndroid Build Coastguard Worker 522*9880d681SAndroid Build Coastguard Worker//===---------------------------------------------------------------------===// 523*9880d681SAndroid Build Coastguard Worker 524*9880d681SAndroid Build Coastguard Workervoid foo(float *data, float d) { 525*9880d681SAndroid Build Coastguard Worker long i; 526*9880d681SAndroid Build Coastguard Worker for (i = 0; i < 8000; i++) 527*9880d681SAndroid Build Coastguard Worker data[i] = d; 528*9880d681SAndroid Build Coastguard Worker} 529*9880d681SAndroid Build Coastguard Workervoid foo2(float *data, float d) { 530*9880d681SAndroid Build Coastguard Worker long i; 531*9880d681SAndroid Build Coastguard Worker data--; 532*9880d681SAndroid Build Coastguard Worker for (i = 0; i < 8000; i++) { 533*9880d681SAndroid Build Coastguard Worker data[1] = d; 534*9880d681SAndroid Build Coastguard Worker data++; 535*9880d681SAndroid Build Coastguard Worker } 536*9880d681SAndroid Build Coastguard Worker} 537*9880d681SAndroid Build Coastguard Worker 538*9880d681SAndroid Build Coastguard WorkerThese compile to: 539*9880d681SAndroid Build Coastguard Worker 540*9880d681SAndroid Build Coastguard Worker_foo: 541*9880d681SAndroid Build Coastguard Worker li r2, 0 542*9880d681SAndroid Build Coastguard WorkerLBB1_1: ; bb 543*9880d681SAndroid Build Coastguard Worker addi r4, r2, 4 544*9880d681SAndroid Build Coastguard Worker stfsx f1, r3, r2 545*9880d681SAndroid Build Coastguard Worker cmplwi cr0, r4, 32000 546*9880d681SAndroid Build Coastguard Worker mr r2, r4 547*9880d681SAndroid Build Coastguard Worker bne cr0, LBB1_1 ; bb 548*9880d681SAndroid Build Coastguard Worker blr 549*9880d681SAndroid Build Coastguard Worker_foo2: 550*9880d681SAndroid Build Coastguard Worker li r2, 0 551*9880d681SAndroid Build Coastguard WorkerLBB2_1: ; bb 552*9880d681SAndroid Build Coastguard Worker addi r4, r2, 4 553*9880d681SAndroid Build Coastguard Worker stfsx f1, r3, r2 554*9880d681SAndroid Build Coastguard Worker cmplwi cr0, r4, 32000 555*9880d681SAndroid Build Coastguard Worker mr r2, r4 556*9880d681SAndroid Build Coastguard Worker bne cr0, LBB2_1 ; bb 557*9880d681SAndroid Build Coastguard Worker blr 558*9880d681SAndroid Build Coastguard Worker 559*9880d681SAndroid Build Coastguard WorkerThe 'mr' could be eliminated to folding the add into the cmp better. 560*9880d681SAndroid Build Coastguard Worker 561*9880d681SAndroid Build Coastguard Worker//===---------------------------------------------------------------------===// 562*9880d681SAndroid Build Coastguard WorkerCodegen for the following (low-probability) case deteriorated considerably 563*9880d681SAndroid Build Coastguard Workerwhen the correctness fixes for unordered comparisons went in (PR 642, 58871). 564*9880d681SAndroid Build Coastguard WorkerIt should be possible to recover the code quality described in the comments. 565*9880d681SAndroid Build Coastguard Worker 566*9880d681SAndroid Build Coastguard Worker; RUN: llvm-as < %s | llc -march=ppc32 | grep or | count 3 567*9880d681SAndroid Build Coastguard Worker; This should produce one 'or' or 'cror' instruction per function. 568*9880d681SAndroid Build Coastguard Worker 569*9880d681SAndroid Build Coastguard Worker; RUN: llvm-as < %s | llc -march=ppc32 | grep mfcr | count 3 570*9880d681SAndroid Build Coastguard Worker; PR2964 571*9880d681SAndroid Build Coastguard Worker 572*9880d681SAndroid Build Coastguard Workerdefine i32 @test(double %x, double %y) nounwind { 573*9880d681SAndroid Build Coastguard Workerentry: 574*9880d681SAndroid Build Coastguard Worker %tmp3 = fcmp ole double %x, %y ; <i1> [#uses=1] 575*9880d681SAndroid Build Coastguard Worker %tmp345 = zext i1 %tmp3 to i32 ; <i32> [#uses=1] 576*9880d681SAndroid Build Coastguard Worker ret i32 %tmp345 577*9880d681SAndroid Build Coastguard Worker} 578*9880d681SAndroid Build Coastguard Worker 579*9880d681SAndroid Build Coastguard Workerdefine i32 @test2(double %x, double %y) nounwind { 580*9880d681SAndroid Build Coastguard Workerentry: 581*9880d681SAndroid Build Coastguard Worker %tmp3 = fcmp one double %x, %y ; <i1> [#uses=1] 582*9880d681SAndroid Build Coastguard Worker %tmp345 = zext i1 %tmp3 to i32 ; <i32> [#uses=1] 583*9880d681SAndroid Build Coastguard Worker ret i32 %tmp345 584*9880d681SAndroid Build Coastguard Worker} 585*9880d681SAndroid Build Coastguard Worker 586*9880d681SAndroid Build Coastguard Workerdefine i32 @test3(double %x, double %y) nounwind { 587*9880d681SAndroid Build Coastguard Workerentry: 588*9880d681SAndroid Build Coastguard Worker %tmp3 = fcmp ugt double %x, %y ; <i1> [#uses=1] 589*9880d681SAndroid Build Coastguard Worker %tmp34 = zext i1 %tmp3 to i32 ; <i32> [#uses=1] 590*9880d681SAndroid Build Coastguard Worker ret i32 %tmp34 591*9880d681SAndroid Build Coastguard Worker} 592*9880d681SAndroid Build Coastguard Worker 593*9880d681SAndroid Build Coastguard Worker//===---------------------------------------------------------------------===// 594*9880d681SAndroid Build Coastguard Workerfor the following code: 595*9880d681SAndroid Build Coastguard Worker 596*9880d681SAndroid Build Coastguard Workervoid foo (float *__restrict__ a, int *__restrict__ b, int n) { 597*9880d681SAndroid Build Coastguard Worker a[n] = b[n] * 2.321; 598*9880d681SAndroid Build Coastguard Worker} 599*9880d681SAndroid Build Coastguard Worker 600*9880d681SAndroid Build Coastguard Workerwe load b[n] to GPR, then move it VSX register and convert it float. We should 601*9880d681SAndroid Build Coastguard Workeruse vsx scalar integer load instructions to avoid direct moves 602*9880d681SAndroid Build Coastguard Worker 603*9880d681SAndroid Build Coastguard Worker//===----------------------------------------------------------------------===// 604*9880d681SAndroid Build Coastguard Worker; RUN: llvm-as < %s | llc -march=ppc32 | not grep fneg 605*9880d681SAndroid Build Coastguard Worker 606*9880d681SAndroid Build Coastguard Worker; This could generate FSEL with appropriate flags (FSEL is not IEEE-safe, and 607*9880d681SAndroid Build Coastguard Worker; should not be generated except with -enable-finite-only-fp-math or the like). 608*9880d681SAndroid Build Coastguard Worker; With the correctness fixes for PR642 (58871) LowerSELECT_CC would need to 609*9880d681SAndroid Build Coastguard Worker; recognize a more elaborate tree than a simple SETxx. 610*9880d681SAndroid Build Coastguard Worker 611*9880d681SAndroid Build Coastguard Workerdefine double @test_FNEG_sel(double %A, double %B, double %C) { 612*9880d681SAndroid Build Coastguard Worker %D = fsub double -0.000000e+00, %A ; <double> [#uses=1] 613*9880d681SAndroid Build Coastguard Worker %Cond = fcmp ugt double %D, -0.000000e+00 ; <i1> [#uses=1] 614*9880d681SAndroid Build Coastguard Worker %E = select i1 %Cond, double %B, double %C ; <double> [#uses=1] 615*9880d681SAndroid Build Coastguard Worker ret double %E 616*9880d681SAndroid Build Coastguard Worker} 617*9880d681SAndroid Build Coastguard Worker 618*9880d681SAndroid Build Coastguard Worker//===----------------------------------------------------------------------===// 619*9880d681SAndroid Build Coastguard WorkerThe save/restore sequence for CR in prolog/epilog is terrible: 620*9880d681SAndroid Build Coastguard Worker- Each CR subreg is saved individually, rather than doing one save as a unit. 621*9880d681SAndroid Build Coastguard Worker- On Darwin, the save is done after the decrement of SP, which means the offset 622*9880d681SAndroid Build Coastguard Workerfrom SP of the save slot can be too big for a store instruction, which means we 623*9880d681SAndroid Build Coastguard Workerneed an additional register (currently hacked in 96015+96020; the solution there 624*9880d681SAndroid Build Coastguard Workeris correct, but poor). 625*9880d681SAndroid Build Coastguard Worker- On SVR4 the same thing can happen, and I don't think saving before the SP 626*9880d681SAndroid Build Coastguard Workerdecrement is safe on that target, as there is no red zone. This is currently 627*9880d681SAndroid Build Coastguard Workerbroken AFAIK, although it's not a target I can exercise. 628*9880d681SAndroid Build Coastguard WorkerThe following demonstrates the problem: 629*9880d681SAndroid Build Coastguard Workerextern void bar(char *p); 630*9880d681SAndroid Build Coastguard Workervoid foo() { 631*9880d681SAndroid Build Coastguard Worker char x[100000]; 632*9880d681SAndroid Build Coastguard Worker bar(x); 633*9880d681SAndroid Build Coastguard Worker __asm__("" ::: "cr2"); 634*9880d681SAndroid Build Coastguard Worker} 635*9880d681SAndroid Build Coastguard Worker 636*9880d681SAndroid Build Coastguard Worker//===-------------------------------------------------------------------------=== 637*9880d681SAndroid Build Coastguard WorkerNaming convention for instruction formats is very haphazard. 638*9880d681SAndroid Build Coastguard WorkerWe have agreed on a naming scheme as follows: 639*9880d681SAndroid Build Coastguard Worker 640*9880d681SAndroid Build Coastguard Worker<INST_form>{_<OP_type><OP_len>}+ 641*9880d681SAndroid Build Coastguard Worker 642*9880d681SAndroid Build Coastguard WorkerWhere: 643*9880d681SAndroid Build Coastguard WorkerINST_form is the instruction format (X-form, etc.) 644*9880d681SAndroid Build Coastguard WorkerOP_type is the operand type - one of OPC (opcode), RD (register destination), 645*9880d681SAndroid Build Coastguard Worker RS (register source), 646*9880d681SAndroid Build Coastguard Worker RDp (destination register pair), 647*9880d681SAndroid Build Coastguard Worker RSp (source register pair), IM (immediate), 648*9880d681SAndroid Build Coastguard Worker XO (extended opcode) 649*9880d681SAndroid Build Coastguard WorkerOP_len is the length of the operand in bits 650*9880d681SAndroid Build Coastguard Worker 651*9880d681SAndroid Build Coastguard WorkerVSX register operands would be of length 6 (split across two fields), 652*9880d681SAndroid Build Coastguard Workercondition register fields of length 3. 653*9880d681SAndroid Build Coastguard WorkerWe would not need denote reserved fields in names of instruction formats. 654*9880d681SAndroid Build Coastguard Worker 655*9880d681SAndroid Build Coastguard Worker//===----------------------------------------------------------------------===// 656*9880d681SAndroid Build Coastguard Worker 657*9880d681SAndroid Build Coastguard WorkerInstruction fusion was introduced in ISA 2.06 and more opportunities added in 658*9880d681SAndroid Build Coastguard WorkerISA 2.07. LLVM needs to add infrastructure to recognize fusion opportunities 659*9880d681SAndroid Build Coastguard Workerand force instruction pairs to be scheduled together. 660*9880d681SAndroid Build Coastguard Worker 661