diff --git a/llvm/lib/Target/RISCV/GISel/RISCVLegalizerInfo.cpp b/llvm/lib/Target/RISCV/GISel/RISCVLegalizerInfo.cpp --- a/llvm/lib/Target/RISCV/GISel/RISCVLegalizerInfo.cpp +++ b/llvm/lib/Target/RISCV/GISel/RISCVLegalizerInfo.cpp @@ -22,6 +22,7 @@ RISCVLegalizerInfo::RISCVLegalizerInfo(const RISCVSubtarget &ST) { const unsigned XLen = ST.getXLen(); const LLT XLenLLT = LLT::scalar(XLen); + const LLT p0 = LLT::pointer(0, XLen); using namespace TargetOpcode; @@ -86,7 +87,7 @@ .clampScalar(0, XLenLLT, XLenLLT); getActionDefinitionsBuilder(G_ICMP) - .legalFor({{XLenLLT, XLenLLT}}) + .legalFor({{XLenLLT, XLenLLT}, {XLenLLT, p0}}) .widenScalarToNextPow2(1) .clampScalar(1, XLenLLT, XLenLLT) .clampScalar(0, XLenLLT, XLenLLT); diff --git a/llvm/test/CodeGen/RISCV/GlobalISel/legalizer/rv32/legalize-icmp.mir b/llvm/test/CodeGen/RISCV/GlobalISel/legalizer/rv32/legalize-icmp.mir --- a/llvm/test/CodeGen/RISCV/GlobalISel/legalizer/rv32/legalize-icmp.mir +++ b/llvm/test/CodeGen/RISCV/GlobalISel/legalizer/rv32/legalize-icmp.mir @@ -1625,3 +1625,21 @@ PseudoRET implicit $x10 ... +--- +name: cmp_eq_ptr +body: | + bb.0.entry: + ; CHECK-LABEL: name: cmp_eq_ptr + ; CHECK: [[COPY:%[0-9]+]]:_(p0) = COPY $x10 + ; CHECK-NEXT: [[COPY1:%[0-9]+]]:_(p0) = COPY $x11 + ; CHECK-NEXT: [[ICMP:%[0-9]+]]:_(s32) = G_ICMP intpred(eq), [[COPY]](p0), [[COPY1]] + ; CHECK-NEXT: $x10 = COPY [[ICMP]](s32) + ; CHECK-NEXT: PseudoRET implicit $x10 + %0:_(p0) = COPY $x10 + %1:_(p0) = COPY $x11 + %2:_(s1) = G_ICMP intpred(eq), %0(p0), %1 + %3:_(s32) = G_ANYEXT %2(s1) + $x10 = COPY %3(s32) + PseudoRET implicit $x10 + +... diff --git a/llvm/test/CodeGen/RISCV/GlobalISel/legalizer/rv64/legalize-icmp.mir b/llvm/test/CodeGen/RISCV/GlobalISel/legalizer/rv64/legalize-icmp.mir --- a/llvm/test/CodeGen/RISCV/GlobalISel/legalizer/rv64/legalize-icmp.mir +++ b/llvm/test/CodeGen/RISCV/GlobalISel/legalizer/rv64/legalize-icmp.mir @@ -1857,3 +1857,21 @@ PseudoRET implicit $x10 ... +--- +name: cmp_ne_ptr +body: | + bb.0.entry: + ; CHECK-LABEL: name: cmp_ne_ptr + ; CHECK: [[COPY:%[0-9]+]]:_(p0) = COPY $x10 + ; CHECK-NEXT: [[COPY1:%[0-9]+]]:_(p0) = COPY $x11 + ; CHECK-NEXT: [[ICMP:%[0-9]+]]:_(s64) = G_ICMP intpred(ne), [[COPY]](p0), [[COPY1]] + ; CHECK-NEXT: $x10 = COPY [[ICMP]](s64) + ; CHECK-NEXT: PseudoRET implicit $x10 + %0:_(p0) = COPY $x10 + %1:_(p0) = COPY $x11 + %2:_(s1) = G_ICMP intpred(ne), %0(p0), %1 + %3:_(s64) = G_ANYEXT %2(s1) + $x10 = COPY %3(s64) + PseudoRET implicit $x10 + +...