diff --git a/llvm/lib/Target/X86/X86LegalizerInfo.cpp b/llvm/lib/Target/X86/X86LegalizerInfo.cpp --- a/llvm/lib/Target/X86/X86LegalizerInfo.cpp +++ b/llvm/lib/Target/X86/X86LegalizerInfo.cpp @@ -348,6 +348,11 @@ .minScalar(0, LLT::scalar(32)) .libcall(); + getActionDefinitionsBuilder(G_FREEZE) + .legalFor({s8, s16, s32, s64, p0}) + .widenScalarToNextPow2(0, /*Min=*/8) + .clampScalar(0, s8, sMaxScalar); + setLegalizerInfo32bit(); setLegalizerInfo64bit(); setLegalizerInfoSSE1(); diff --git a/llvm/test/CodeGen/X86/GlobalISel/legalize-freeze.mir b/llvm/test/CodeGen/X86/GlobalISel/legalize-freeze.mir new file mode 100644 --- /dev/null +++ b/llvm/test/CodeGen/X86/GlobalISel/legalize-freeze.mir @@ -0,0 +1,98 @@ +# NOTE: Assertions have been autogenerated by utils/update_mir_test_checks.py UTC_ARGS: --version 2 +# RUN: llc -verify-machineinstrs -mtriple=x86_64-linux-gnu -run-pass=legalizer %s -o - | FileCheck %s + +# test freeze + +... +--- +name: test_freezep0 +body: | + bb.1: + ; CHECK-LABEL: name: test_freezep0 + ; CHECK: [[DEF:%[0-9]+]]:_(p0) = IMPLICIT_DEF + ; CHECK-NEXT: [[FREEZE:%[0-9]+]]:_(p0) = G_FREEZE [[DEF]] + ; CHECK-NEXT: [[COPY:%[0-9]+]]:_(p0) = COPY [[FREEZE]](p0) + ; CHECK-NEXT: RET 0, implicit [[COPY]](p0) + %0:_(p0) = IMPLICIT_DEF + %1:_(p0) = G_FREEZE %0 + %2:_(p0) = COPY %1(p0) + RET 0, implicit %2 + +... +--- +name: test_freeze64 +body: | + bb.1: + ; CHECK-LABEL: name: test_freeze64 + ; CHECK: [[DEF:%[0-9]+]]:_(s64) = IMPLICIT_DEF + ; CHECK-NEXT: [[FREEZE:%[0-9]+]]:_(s64) = G_FREEZE [[DEF]] + ; CHECK-NEXT: [[COPY:%[0-9]+]]:_(s64) = COPY [[FREEZE]](s64) + ; CHECK-NEXT: RET 0, implicit [[COPY]](s64) + %0:_(s64) = IMPLICIT_DEF + %1:_(s64) = G_FREEZE %0 + %2:_(s64) = COPY %1(s64) + RET 0, implicit %2 + +... +--- +name: test_freeze48 +body: | + bb.1: + ; CHECK-LABEL: name: test_freeze48 + ; CHECK: [[DEF:%[0-9]+]]:_(s48) = IMPLICIT_DEF + ; CHECK-NEXT: [[ANYEXT:%[0-9]+]]:_(s64) = G_ANYEXT [[DEF]](s48) + ; CHECK-NEXT: [[FREEZE:%[0-9]+]]:_(s64) = G_FREEZE [[ANYEXT]] + ; CHECK-NEXT: [[TRUNC:%[0-9]+]]:_(s48) = G_TRUNC [[FREEZE]](s64) + ; CHECK-NEXT: [[COPY:%[0-9]+]]:_(s48) = COPY [[TRUNC]](s48) + ; CHECK-NEXT: RET 0, implicit [[COPY]](s48) + %0:_(s48) = IMPLICIT_DEF + %1:_(s48) = G_FREEZE %0 + %2:_(s48) = COPY %1(s48) + RET 0, implicit %2 + +... +--- +name: test_freeze32 +body: | + bb.1: + ; CHECK-LABEL: name: test_freeze32 + ; CHECK: [[DEF:%[0-9]+]]:_(s32) = IMPLICIT_DEF + ; CHECK-NEXT: [[FREEZE:%[0-9]+]]:_(s32) = G_FREEZE [[DEF]] + ; CHECK-NEXT: [[COPY:%[0-9]+]]:_(s32) = COPY [[FREEZE]](s32) + ; CHECK-NEXT: RET 0, implicit [[COPY]](s32) + %0:_(s32) = IMPLICIT_DEF + %1:_(s32) = G_FREEZE %0 + %2:_(s32) = COPY %1(s32) + RET 0, implicit %2 + +... +--- +name: test_freeze16 +body: | + bb.1: + ; CHECK-LABEL: name: test_freeze16 + ; CHECK: [[DEF:%[0-9]+]]:_(s16) = IMPLICIT_DEF + ; CHECK-NEXT: [[FREEZE:%[0-9]+]]:_(s16) = G_FREEZE [[DEF]] + ; CHECK-NEXT: [[COPY:%[0-9]+]]:_(s16) = COPY [[FREEZE]](s16) + ; CHECK-NEXT: RET 0, implicit [[COPY]](s16) + %0:_(s16) = IMPLICIT_DEF + %1:_(s16) = G_FREEZE %0 + %2:_(s16) = COPY %1(s16) + RET 0, implicit %2 + +... +--- +name: test_freeze8 +body: | + bb.1: + ; CHECK-LABEL: name: test_freeze8 + ; CHECK: [[DEF:%[0-9]+]]:_(s8) = IMPLICIT_DEF + ; CHECK-NEXT: [[FREEZE:%[0-9]+]]:_(s8) = G_FREEZE [[DEF]] + ; CHECK-NEXT: [[COPY:%[0-9]+]]:_(s8) = COPY [[FREEZE]](s8) + ; CHECK-NEXT: RET 0, implicit [[COPY]](s8) + %0:_(s8) = IMPLICIT_DEF + %1:_(s8) = G_FREEZE %0 + %2:_(s8) = COPY %1(s8) + RET 0, implicit %2 + +...