]> granicus.if.org Git - llvm/commitdiff
[PowerPC][Peephole] Check if `extsw`'s second operand is a virtual register
authorKai Luo <lkail@cn.ibm.com>
Fri, 2 Aug 2019 03:14:17 +0000 (03:14 +0000)
committerKai Luo <lkail@cn.ibm.com>
Fri, 2 Aug 2019 03:14:17 +0000 (03:14 +0000)
Summary:
When combining `extsw` and `sldi` in `PPCMIPeephole`, we have to check
if `extsw`'s second operand is a virtual register, otherwise we might
get miscompile.

Differential Revision: https://reviews.llvm.org/D65315

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@367645 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Target/PowerPC/PPCMIPeephole.cpp
test/CodeGen/MIR/PowerPC/peephole-miscompile-extswsli.mir

index 1b48bbaf1f44eb1d530a24511ad68dddeab52ffb..fe4f351e639819f28b687f2d937fb1054681c145 100644 (file)
@@ -1426,6 +1426,12 @@ bool PPCMIPeephole::combineSEXTAndSHL(MachineInstr &MI,
   if (!MRI->hasOneNonDBGUse(SrcReg))
     return false;
 
+  assert(SrcMI->getNumOperands() == 2 && "EXTSW should have 2 operands");
+  assert(SrcMI->getOperand(1).isReg() &&
+         "EXTSW's second operand should be a register");
+  if (!Register::isVirtualRegister(SrcMI->getOperand(1).getReg()))
+    return false;
+
   LLVM_DEBUG(dbgs() << "Combining pair: ");
   LLVM_DEBUG(SrcMI->dump());
   LLVM_DEBUG(MI.dump());
index 5c78e408ffc765812f5972afc6e49a2a80cd9009..76fde05be70a7f690a464559f90cf5907a1a556e 100644 (file)
@@ -20,10 +20,11 @@ body:             |
   ; CHECK:   B %bb.1
   ; CHECK: bb.1:
   ; CHECK:   liveins: $x3
+  ; CHECK:   [[EXTSW:%[0-9]+]]:g8rc = EXTSW $x3
   ; CHECK:   [[RLDICR:%[0-9]+]]:g8rc = RLDICR [[ANDIo8_]], 2, 61
   ; CHECK:   $x3 = COPY [[RLDICR]]
-  ; CHECK:   [[EXTSWSLI:%[0-9]+]]:g8rc = EXTSWSLI $x3, 2, implicit-def $carry
-  ; CHECK:   [[ADD8_:%[0-9]+]]:g8rc = ADD8 [[COPY3]], [[EXTSWSLI]]
+  ; CHECK:   [[RLDICR1:%[0-9]+]]:g8rc = RLDICR [[EXTSW]], 2, 61
+  ; CHECK:   [[ADD8_:%[0-9]+]]:g8rc = ADD8 [[COPY3]], [[RLDICR1]]
   ; CHECK:   $x3 = COPY [[ADD8_]]
   ; CHECK:   BLR8 implicit $lr8, implicit $rm, implicit $x3
   ; CHECK: bb.2: