diff --git a/llvm/lib/CodeGen/SelectionDAG/DAGCombiner.cpp b/llvm/lib/CodeGen/SelectionDAG/DAGCombiner.cpp --- a/llvm/lib/CodeGen/SelectionDAG/DAGCombiner.cpp +++ b/llvm/lib/CodeGen/SelectionDAG/DAGCombiner.cpp @@ -10464,6 +10464,14 @@ return DAG.getNode(ISD::SHL, DL, VT, Cond, ShAmtC); } + // select Cond, 0, Pow2 --> (zext(not Cond) << log2(Pow2)) + if (C1Val.isZero() && C2Val.isPowerOf2()) { + SDValue NotCond = DAG.getNOT(DL, Cond, MVT::i1); + NotCond = DAG.getZExtOrTrunc(NotCond, DL, VT); + SDValue ShAmtC = DAG.getShiftAmountConstant(C2Val.exactLogBase2(), VT, DL); + return DAG.getNode(ISD::SHL, DL, VT, NotCond, ShAmtC); + } + // select Cond, -1, C --> or (sext Cond), C if (C1->isAllOnes()) { Cond = DAG.getSExtOrTrunc(Cond, DL, VT); @@ -10477,6 +10485,16 @@ return DAG.getNode(ISD::OR, DL, VT, NotCond, N1); } + // select Cond, C1, C2 --> (zext(Cond) << log2(C1 - C2)) + C2 + bool OV; + APInt Diff = C1Val.ssub_ov(C2Val, OV); + if (!OV && Diff.isPowerOf2()) { + Cond = DAG.getZExtOrTrunc(Cond, DL, VT); + SDValue ShAmtC = DAG.getShiftAmountConstant(Diff.exactLogBase2(), VT, DL); + Cond = DAG.getNode(ISD::SHL, DL, VT, Cond, ShAmtC); + return DAG.getNode(ISD::ADD, DL, VT, Cond, N2); + } + if (SDValue V = foldSelectOfConstantsUsingSra(N, DAG)) return V; diff --git a/llvm/test/CodeGen/PowerPC/fp-strict-conv-f128.ll b/llvm/test/CodeGen/PowerPC/fp-strict-conv-f128.ll --- a/llvm/test/CodeGen/PowerPC/fp-strict-conv-f128.ll +++ b/llvm/test/CodeGen/PowerPC/fp-strict-conv-f128.ll @@ -616,14 +616,15 @@ ; P8-NEXT: xxlxor f3, f3, f3 ; P8-NEXT: std r30, 112(r1) # 8-byte Folded Spill ; P8-NEXT: lfs f0, .LCPI13_0@toc@l(r3) -; P8-NEXT: lis r3, -32768 +; P8-NEXT: li r3, 1 ; P8-NEXT: fcmpo cr0, f2, f3 ; P8-NEXT: xxlxor f3, f3, f3 ; P8-NEXT: fcmpo cr1, f1, f0 ; P8-NEXT: crand 4*cr5+lt, 4*cr1+eq, lt ; P8-NEXT: crandc 4*cr5+gt, 4*cr1+lt, 4*cr1+eq ; P8-NEXT: cror 4*cr5+lt, 4*cr5+gt, 4*cr5+lt -; P8-NEXT: isel r30, 0, r3, 4*cr5+lt +; P8-NEXT: isel r3, 0, r3, 4*cr5+lt +; P8-NEXT: slwi r30, r3, 31 ; P8-NEXT: bc 12, 4*cr5+lt, .LBB13_2 ; P8-NEXT: # %bb.1: # %entry ; P8-NEXT: fmr f3, f0 @@ -659,13 +660,14 @@ ; P9-NEXT: xxlxor f3, f3, f3 ; P9-NEXT: lfs f0, .LCPI13_0@toc@l(r3) ; P9-NEXT: fcmpo cr1, f2, f3 -; P9-NEXT: lis r3, -32768 +; P9-NEXT: li r3, 1 ; P9-NEXT: fcmpo cr0, f1, f0 ; P9-NEXT: xxlxor f3, f3, f3 ; P9-NEXT: crand 4*cr5+lt, eq, 4*cr1+lt ; P9-NEXT: crandc 4*cr5+gt, lt, eq ; P9-NEXT: cror 4*cr5+lt, 4*cr5+gt, 4*cr5+lt -; P9-NEXT: isel r30, 0, r3, 4*cr5+lt +; P9-NEXT: isel r3, 0, r3, 4*cr5+lt +; P9-NEXT: slwi r30, r3, 31 ; P9-NEXT: bc 12, 4*cr5+lt, .LBB13_2 ; P9-NEXT: # %bb.1: # %entry ; P9-NEXT: fmr f3, f0 @@ -722,9 +724,10 @@ ; NOVSX-NEXT: mtfsf 1, f0 ; NOVSX-NEXT: fctiwz f0, f1 ; NOVSX-NEXT: stfiwx f0, 0, r3 -; NOVSX-NEXT: lis r3, -32768 -; NOVSX-NEXT: lwz r4, 44(r1) +; NOVSX-NEXT: li r3, 1 ; NOVSX-NEXT: isel r3, 0, r3, 4*cr2+lt +; NOVSX-NEXT: lwz r4, 44(r1) +; NOVSX-NEXT: slwi r3, r3, 31 ; NOVSX-NEXT: xor r3, r4, r3 ; NOVSX-NEXT: clrldi r3, r3, 32 ; NOVSX-NEXT: addi r1, r1, 48 diff --git a/llvm/test/CodeGen/PowerPC/nofpexcept.ll b/llvm/test/CodeGen/PowerPC/nofpexcept.ll --- a/llvm/test/CodeGen/PowerPC/nofpexcept.ll +++ b/llvm/test/CodeGen/PowerPC/nofpexcept.ll @@ -117,9 +117,10 @@ ; CHECK-NEXT: [[COPY13:%[0-9]+]]:crbitrc = COPY [[FCMPOD]].sub_lt ; CHECK-NEXT: [[CRANDC:%[0-9]+]]:crbitrc = CRANDC killed [[COPY13]], killed [[COPY12]] ; CHECK-NEXT: [[CROR:%[0-9]+]]:crbitrc = CROR killed [[CRANDC]], killed [[CRAND]] - ; CHECK-NEXT: [[LIS:%[0-9]+]]:gprc_and_gprc_nor0 = LIS 32768 - ; CHECK-NEXT: [[LI:%[0-9]+]]:gprc_and_gprc_nor0 = LI 0 - ; CHECK-NEXT: [[ISEL:%[0-9]+]]:gprc = ISEL [[LI]], [[LIS]], [[CROR]] + ; CHECK-NEXT: [[LI:%[0-9]+]]:gprc_and_gprc_nor0 = LI 1 + ; CHECK-NEXT: [[LI1:%[0-9]+]]:gprc_and_gprc_nor0 = LI 0 + ; CHECK-NEXT: [[ISEL:%[0-9]+]]:gprc = ISEL [[LI1]], [[LI]], [[CROR]] + ; CHECK-NEXT: [[RLWINM:%[0-9]+]]:gprc = RLWINM killed [[ISEL]], 31, 0, 0 ; CHECK-NEXT: BC [[CROR]], %bb.2 ; CHECK-NEXT: {{ $}} ; CHECK-NEXT: bb.1.entry: @@ -140,11 +141,11 @@ ; CHECK-NEXT: [[MFFS1:%[0-9]+]]:f8rc = MFFS implicit $rm ; CHECK-NEXT: MTFSB1 31, implicit-def $rm, implicit-def $rm ; CHECK-NEXT: MTFSB0 30, implicit-def $rm, implicit-def $rm - ; CHECK-NEXT: %37:f8rc = nofpexcept FADD [[COPY15]], [[COPY14]], implicit $rm + ; CHECK-NEXT: %38:f8rc = nofpexcept FADD [[COPY15]], [[COPY14]], implicit $rm ; CHECK-NEXT: MTFSFb 1, [[MFFS1]], implicit-def $rm - ; CHECK-NEXT: %38:vsfrc = nofpexcept XSCVDPSXWS killed %37, implicit $rm - ; CHECK-NEXT: [[MFVSRWZ3:%[0-9]+]]:gprc = MFVSRWZ killed %38 - ; CHECK-NEXT: [[XOR:%[0-9]+]]:gprc = XOR killed [[MFVSRWZ3]], killed [[ISEL]] + ; CHECK-NEXT: %39:vsfrc = nofpexcept XSCVDPSXWS killed %38, implicit $rm + ; CHECK-NEXT: [[MFVSRWZ3:%[0-9]+]]:gprc = MFVSRWZ killed %39 + ; CHECK-NEXT: [[XOR:%[0-9]+]]:gprc = XOR killed [[MFVSRWZ3]], killed [[RLWINM]] ; CHECK-NEXT: STW killed [[XOR]], 0, [[COPY1]] :: (volatile store (s32) into %ir.addr1) ; CHECK-NEXT: BLR8 implicit $lr8, implicit $rm entry: diff --git a/llvm/test/CodeGen/PowerPC/ppcf128-constrained-fp-intrinsics.ll b/llvm/test/CodeGen/PowerPC/ppcf128-constrained-fp-intrinsics.ll --- a/llvm/test/CodeGen/PowerPC/ppcf128-constrained-fp-intrinsics.ll +++ b/llvm/test/CodeGen/PowerPC/ppcf128-constrained-fp-intrinsics.ll @@ -1293,14 +1293,15 @@ ; PC64LE-NEXT: addis 3, 2, .LCPI31_0@toc@ha ; PC64LE-NEXT: xxlxor 3, 3, 3 ; PC64LE-NEXT: lfs 0, .LCPI31_0@toc@l(3) -; PC64LE-NEXT: lis 3, -32768 +; PC64LE-NEXT: li 3, 1 ; PC64LE-NEXT: fcmpo 0, 2, 3 ; PC64LE-NEXT: xxlxor 3, 3, 3 ; PC64LE-NEXT: fcmpo 1, 1, 0 ; PC64LE-NEXT: crand 20, 6, 0 ; PC64LE-NEXT: crandc 21, 4, 6 ; PC64LE-NEXT: cror 20, 21, 20 -; PC64LE-NEXT: isel 30, 0, 3, 20 +; PC64LE-NEXT: isel 3, 0, 3, 20 +; PC64LE-NEXT: slwi 30, 3, 31 ; PC64LE-NEXT: bc 12, 20, .LBB31_2 ; PC64LE-NEXT: # %bb.1: # %entry ; PC64LE-NEXT: fmr 3, 0 @@ -1332,13 +1333,14 @@ ; PC64LE9-NEXT: xxlxor 3, 3, 3 ; PC64LE9-NEXT: lfs 0, .LCPI31_0@toc@l(3) ; PC64LE9-NEXT: fcmpo 1, 2, 3 -; PC64LE9-NEXT: lis 3, -32768 +; PC64LE9-NEXT: li 3, 1 ; PC64LE9-NEXT: fcmpo 0, 1, 0 ; PC64LE9-NEXT: xxlxor 3, 3, 3 ; PC64LE9-NEXT: crand 20, 2, 4 ; PC64LE9-NEXT: crandc 21, 0, 2 ; PC64LE9-NEXT: cror 20, 21, 20 -; PC64LE9-NEXT: isel 30, 0, 3, 20 +; PC64LE9-NEXT: isel 3, 0, 3, 20 +; PC64LE9-NEXT: slwi 30, 3, 31 ; PC64LE9-NEXT: bc 12, 20, .LBB31_2 ; PC64LE9-NEXT: # %bb.1: # %entry ; PC64LE9-NEXT: fmr 3, 0 @@ -1385,13 +1387,14 @@ ; PC64-NEXT: nop ; PC64-NEXT: mffs 0 ; PC64-NEXT: mtfsb1 31 -; PC64-NEXT: lis 4, -32768 +; PC64-NEXT: li 4, 1 ; PC64-NEXT: bc 12, 8, .LBB31_3 ; PC64-NEXT: b .LBB31_4 ; PC64-NEXT: .LBB31_3: # %entry ; PC64-NEXT: li 4, 0 ; PC64-NEXT: .LBB31_4: # %entry ; PC64-NEXT: mtfsb0 30 +; PC64-NEXT: slwi 4, 4, 31 ; PC64-NEXT: fadd 1, 2, 1 ; PC64-NEXT: mtfsf 1, 0 ; PC64-NEXT: fctiwz 0, 1 diff --git a/llvm/test/CodeGen/PowerPC/pr49509.ll b/llvm/test/CodeGen/PowerPC/pr49509.ll --- a/llvm/test/CodeGen/PowerPC/pr49509.ll +++ b/llvm/test/CodeGen/PowerPC/pr49509.ll @@ -16,39 +16,31 @@ ; CHECK-NEXT: .LBB0_2: # %bb1 ; CHECK-NEXT: bclr 4, 20, 0 ; CHECK-NEXT: # %bb.3: # %bb66 +; CHECK-NEXT: lbz 3, 0(3) ; CHECK-NEXT: lwz 4, 12(0) ; CHECK-NEXT: lwz 5, 8(0) +; CHECK-NEXT: cmpwi 3, 0 ; CHECK-NEXT: lwz 6, 0(0) +; CHECK-NEXT: li 3, 1 ; CHECK-NEXT: lwz 7, 4(0) -; CHECK-NEXT: lbz 3, 0(3) -; CHECK-NEXT: and 5, 5, 6 -; CHECK-NEXT: and 4, 4, 7 -; CHECK-NEXT: and 4, 4, 5 -; CHECK-NEXT: cmpwi 3, 0 -; CHECK-NEXT: lis 3, 256 -; CHECK-NEXT: lis 7, 512 ; CHECK-NEXT: bc 12, 2, .LBB0_4 ; CHECK-NEXT: b .LBB0_5 ; CHECK-NEXT: .LBB0_4: # %bb66 ; CHECK-NEXT: li 3, 0 ; CHECK-NEXT: .LBB0_5: # %bb66 -; CHECK-NEXT: cmpwi 1, 4, -1 -; CHECK-NEXT: cmpwi 5, 4, -1 +; CHECK-NEXT: and 5, 5, 6 ; CHECK-NEXT: li 6, 0 -; CHECK-NEXT: bc 12, 6, .LBB0_6 +; CHECK-NEXT: and 4, 4, 7 +; CHECK-NEXT: and 4, 4, 5 +; CHECK-NEXT: lis 7, 512 +; CHECK-NEXT: slwi 3, 3, 24 +; CHECK-NEXT: cmpwi 4, -1 +; CHECK-NEXT: stw 6, 0(3) +; CHECK-NEXT: bc 12, 2, .LBB0_6 ; CHECK-NEXT: b .LBB0_7 ; CHECK-NEXT: .LBB0_6: # %bb66 ; CHECK-NEXT: addi 3, 7, 0 ; CHECK-NEXT: .LBB0_7: # %bb66 -; CHECK-NEXT: cror 20, 22, 2 -; CHECK-NEXT: stw 3, 0(3) -; CHECK-NEXT: bc 12, 20, .LBB0_9 -; CHECK-NEXT: # %bb.8: # %bb66 -; CHECK-NEXT: ori 3, 6, 0 -; CHECK-NEXT: b .LBB0_10 -; CHECK-NEXT: .LBB0_9: # %bb66 -; CHECK-NEXT: li 3, 0 -; CHECK-NEXT: .LBB0_10: # %bb66 ; CHECK-NEXT: stw 3, 0(3) ; CHECK-NEXT: blr bb: diff --git a/llvm/test/CodeGen/PowerPC/select_const.ll b/llvm/test/CodeGen/PowerPC/select_const.ll --- a/llvm/test/CodeGen/PowerPC/select_const.ll +++ b/llvm/test/CodeGen/PowerPC/select_const.ll @@ -354,22 +354,11 @@ } define i8 @sel_constants_sdiv_constant(i1 %cond) { -; ISEL-LABEL: sel_constants_sdiv_constant: -; ISEL: # %bb.0: -; ISEL-NEXT: andi. 3, 3, 1 -; ISEL-NEXT: li 3, 4 -; ISEL-NEXT: iselgt 3, 0, 3 -; ISEL-NEXT: blr -; -; NO_ISEL-LABEL: sel_constants_sdiv_constant: -; NO_ISEL: # %bb.0: -; NO_ISEL-NEXT: andi. 3, 3, 1 -; NO_ISEL-NEXT: li 3, 4 -; NO_ISEL-NEXT: bc 12, 1, .LBB25_1 -; NO_ISEL-NEXT: blr -; NO_ISEL-NEXT: .LBB25_1: -; NO_ISEL-NEXT: li 3, 0 -; NO_ISEL-NEXT: blr +; ALL-LABEL: sel_constants_sdiv_constant: +; ALL: # %bb.0: +; ALL-NEXT: not 3, 3 +; ALL-NEXT: rlwinm 3, 3, 2, 29, 29 +; ALL-NEXT: blr %sel = select i1 %cond, i8 -4, i8 23 %bo = sdiv i8 %sel, 5 ret i8 %bo @@ -658,24 +647,11 @@ } define i8 @lshr_constant_sel_constants(i1 %cond) { -; ISEL-LABEL: lshr_constant_sel_constants: -; ISEL: # %bb.0: -; ISEL-NEXT: andi. 3, 3, 1 -; ISEL-NEXT: li 4, 16 -; ISEL-NEXT: li 3, 8 -; ISEL-NEXT: iselgt 3, 4, 3 -; ISEL-NEXT: blr -; -; NO_ISEL-LABEL: lshr_constant_sel_constants: -; NO_ISEL: # %bb.0: -; NO_ISEL-NEXT: andi. 3, 3, 1 -; NO_ISEL-NEXT: li 4, 16 -; NO_ISEL-NEXT: li 3, 8 -; NO_ISEL-NEXT: bc 12, 1, .LBB39_1 -; NO_ISEL-NEXT: blr -; NO_ISEL-NEXT: .LBB39_1: -; NO_ISEL-NEXT: addi 3, 4, 0 -; NO_ISEL-NEXT: blr +; ALL-LABEL: lshr_constant_sel_constants: +; ALL: # %bb.0: +; ALL-NEXT: rlwinm 3, 3, 3, 28, 28 +; ALL-NEXT: addi 3, 3, 8 +; ALL-NEXT: blr %sel = select i1 %cond, i8 2, i8 3 %bo = lshr i8 64, %sel ret i8 %bo diff --git a/llvm/test/CodeGen/RISCV/pr58511.ll b/llvm/test/CodeGen/RISCV/pr58511.ll --- a/llvm/test/CodeGen/RISCV/pr58511.ll +++ b/llvm/test/CodeGen/RISCV/pr58511.ll @@ -64,14 +64,12 @@ define i32 @i(i1 %0, i32 %1, ptr %2) { ; CHECK-LABEL: i: ; CHECK: # %bb.0: # %BB -; CHECK-NEXT: andi a0, a0, 1 ; CHECK-NEXT: slliw a3, a1, 11 ; CHECK-NEXT: slliw a1, a1, 12 ; CHECK-NEXT: subw a1, a1, a3 -; CHECK-NEXT: addi a0, a0, -1 -; CHECK-NEXT: lui a3, 1 -; CHECK-NEXT: addiw a3, a3, -2048 -; CHECK-NEXT: and a0, a0, a3 +; CHECK-NEXT: not a0, a0 +; CHECK-NEXT: andi a0, a0, 1 +; CHECK-NEXT: slli a0, a0, 11 ; CHECK-NEXT: sw a1, 0(a2) ; CHECK-NEXT: ret BB: