[llvm] r365511 - [RISCV] Fix ICE in isDesirableToCommuteWithShift

Sam Elliott via llvm-commits llvm-commits at lists.llvm.org
Tue Jul 9 09:24:16 PDT 2019


Author: lenary
Date: Tue Jul  9 09:24:16 2019
New Revision: 365511

URL: http://llvm.org/viewvc/llvm-project?rev=365511&view=rev
Log:
[RISCV] Fix ICE in isDesirableToCommuteWithShift

Summary:
There was an error being thrown from isDesirableToCommuteWithShift in
some tests. This was tracked down to the method being called before
legalisation, with an extended value type, not a machine value type.

In the case I diagnosed, the error was only hit with an instruction sequence
involving `i24`s in the add and shift. `i24` is not a Machine ValueType, it is
instead an Extended ValueType which was causing the issue.

I have added a test to cover this case, and fixed the error in the callback.

Reviewers: asb, luismarques

Reviewed By: asb

Subscribers: hiraditya, rbar, johnrusso, simoncook, apazos, sabuasal, niosHD, kito-cheng, shiva0217, jrtc27, MaskRay, zzheng, edward-jones, rogfer01, MartinMosbeck, brucehoult, the_o, rkruppe, PkmX, jocewei, psnobl, benna, Jim, llvm-commits

Tags: #llvm

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

Modified:
    llvm/trunk/lib/Target/RISCV/RISCVISelLowering.cpp
    llvm/trunk/test/CodeGen/RISCV/add-before-shl.ll

Modified: llvm/trunk/lib/Target/RISCV/RISCVISelLowering.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Target/RISCV/RISCVISelLowering.cpp?rev=365511&r1=365510&r2=365511&view=diff
==============================================================================
--- llvm/trunk/lib/Target/RISCV/RISCVISelLowering.cpp (original)
+++ llvm/trunk/lib/Target/RISCV/RISCVISelLowering.cpp Tue Jul  9 09:24:16 2019
@@ -995,7 +995,7 @@ bool RISCVTargetLowering::isDesirableToC
   //   (shl (add x, c1), c2) -> (add (shl x, c2), c1 << c2)
   //   (shl (or x, c1), c2) -> (or (shl x, c2), c1 << c2)
   SDValue N0 = N->getOperand(0);
-  MVT Ty = N0.getSimpleValueType();
+  EVT Ty = N0.getValueType();
   if (Ty.isScalarInteger() &&
       (N0.getOpcode() == ISD::ADD || N0.getOpcode() == ISD::OR)) {
     auto *C1 = dyn_cast<ConstantSDNode>(N0->getOperand(1));

Modified: llvm/trunk/test/CodeGen/RISCV/add-before-shl.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/CodeGen/RISCV/add-before-shl.ll?rev=365511&r1=365510&r2=365511&view=diff
==============================================================================
--- llvm/trunk/test/CodeGen/RISCV/add-before-shl.ll (original)
+++ llvm/trunk/test/CodeGen/RISCV/add-before-shl.ll Tue Jul  9 09:24:16 2019
@@ -72,3 +72,22 @@ define signext i32 @add_huge_const(i32 s
   %3 = ashr i32 %2, 16
   ret i32 %3
 }
+
+define signext i24 @add_non_machine_type(i24 signext %a) nounwind {
+; RV32I-LABEL: add_non_machine_type:
+; RV32I:       # %bb.0:
+; RV32I-NEXT:    addi a0, a0, 256
+; RV32I-NEXT:    slli a0, a0, 20
+; RV32I-NEXT:    srai a0, a0, 8
+; RV32I-NEXT:    ret
+;
+; RV64I-LABEL: add_non_machine_type:
+; RV64I:       # %bb.0:
+; RV64I-NEXT:    addi a0, a0, 256
+; RV64I-NEXT:    slli a0, a0, 52
+; RV64I-NEXT:    srai a0, a0, 40
+; RV64I-NEXT:    ret
+  %1 = add i24 %a, 256
+  %2 = shl i24 %1, 12
+  ret i24 %2
+}




More information about the llvm-commits mailing list