Index: llvm/lib/Target/AArch64/GISel/AArch64LegalizerInfo.cpp =================================================================== --- llvm/lib/Target/AArch64/GISel/AArch64LegalizerInfo.cpp +++ llvm/lib/Target/AArch64/GISel/AArch64LegalizerInfo.cpp @@ -490,8 +490,8 @@ getActionDefinitionsBuilder(G_PTRTOINT) .legalForCartesianProduct({s1, s8, s16, s32, s64}, {p0}) - .maxScalar(0, s64) - .widenScalarToNextPow2(0, /*Min*/ 8); + .widenScalarToNextPow2(0) + .clampScalar(0, s64, s64); getActionDefinitionsBuilder(G_INTTOPTR) .unsupportedIf([&](const LegalityQuery &Query) { Index: llvm/test/CodeGen/AArch64/GlobalISel/legalize-ptrtoint.mir =================================================================== --- /dev/null +++ llvm/test/CodeGen/AArch64/GlobalISel/legalize-ptrtoint.mir @@ -0,0 +1,116 @@ +# NOTE: Assertions have been autogenerated by utils/update_mir_test_checks.py +# RUN: llc -mtriple aarch64 -run-pass=legalizer -verify-machineinstrs -o - %s | FileCheck %s + +... +--- +name: p0_s64 +body: | + bb.0: + liveins: $x0 + ; CHECK-LABEL: name: p0_s64 + ; CHECK: %ptr:_(p0) = COPY $x0 + ; CHECK: %int:_(s64) = G_PTRTOINT %ptr(p0) + ; CHECK: $x0 = COPY %int(s64) + ; CHECK: RET_ReallyLR implicit $x0 + %ptr:_(p0) = COPY $x0 + %int:_(s64) = G_PTRTOINT %ptr + $x0 = COPY %int + RET_ReallyLR implicit $x0 +... +--- +name: p0_s32 +body: | + bb.0: + liveins: $x0 + ; CHECK-LABEL: name: p0_s32 + ; CHECK: %ptr:_(p0) = COPY $x0 + ; CHECK: %int:_(s32) = G_PTRTOINT %ptr(p0) + ; CHECK: $w0 = COPY %int(s32) + ; CHECK: RET_ReallyLR implicit $w0 + %ptr:_(p0) = COPY $x0 + %int:_(s32) = G_PTRTOINT %ptr + $w0 = COPY %int + RET_ReallyLR implicit $w0 +... +--- +name: p0_s16 +body: | + bb.0: + liveins: $x0, $h0 + ; CHECK-LABEL: name: p0_s16 + ; CHECK: %ptr:_(p0) = COPY $x0 + ; CHECK: %int:_(s16) = G_PTRTOINT %ptr(p0) + ; CHECK: $h0 = COPY %int(s16) + ; CHECK: RET_ReallyLR implicit $h0 + %ptr:_(p0) = COPY $x0 + %int:_(s16) = G_PTRTOINT %ptr + $h0 = COPY %int + RET_ReallyLR implicit $h0 +... +--- +name: p0_s8 +body: | + bb.0: + liveins: $x0, $b0 + ; CHECK-LABEL: name: p0_s8 + ; CHECK: %ptr:_(p0) = COPY $x0 + ; CHECK: %int:_(s8) = G_PTRTOINT %ptr(p0) + ; CHECK: $b0 = COPY %int(s8) + ; CHECK: RET_ReallyLR implicit $b0 + %ptr:_(p0) = COPY $x0 + %int:_(s8) = G_PTRTOINT %ptr + $b0 = COPY %int + RET_ReallyLR implicit $b0 +... +--- +name: p0_s1 +body: | + bb.0: + liveins: $x0 + ; CHECK-LABEL: name: p0_s1 + ; CHECK: %ptr:_(p0) = COPY $x0 + ; CHECK: %int:_(s1) = G_PTRTOINT %ptr(p0) + ; CHECK: %ext:_(s32) = G_ZEXT %int(s1) + ; CHECK: $w0 = COPY %ext(s32) + ; CHECK: RET_ReallyLR implicit $w0 + %ptr:_(p0) = COPY $x0 + %int:_(s1) = G_PTRTOINT %ptr + %ext:_(s32) = G_ZEXT %int + $w0 = COPY %ext + RET_ReallyLR implicit $w0 +... +--- +name: p0_s128 +body: | + bb.0: + liveins: $x0, $q0 + ; CHECK-LABEL: name: p0_s128 + ; CHECK: %ptr:_(p0) = COPY $x0 + ; CHECK: [[PTRTOINT:%[0-9]+]]:_(s64) = G_PTRTOINT %ptr(p0) + ; CHECK: [[C:%[0-9]+]]:_(s64) = G_CONSTANT i64 0 + ; CHECK: %int:_(s128) = G_MERGE_VALUES [[PTRTOINT]](s64), [[C]](s64) + ; CHECK: $q0 = COPY %int(s128) + ; CHECK: RET_ReallyLR implicit $q0 + %ptr:_(p0) = COPY $x0 + %int:_(s128) = G_PTRTOINT %ptr + $q0 = COPY %int + RET_ReallyLR implicit $q0 +... +--- +name: p0_s88 +body: | + bb.0: + liveins: $x0 + ; CHECK-LABEL: name: p0_s88 + ; CHECK: %ptr:_(p0) = COPY $x0 + ; CHECK: [[PTRTOINT:%[0-9]+]]:_(s64) = G_PTRTOINT %ptr(p0) + ; CHECK: [[C:%[0-9]+]]:_(s64) = G_CONSTANT i64 0 + ; CHECK: %trunc:_(s32) = G_TRUNC [[PTRTOINT]](s64) + ; CHECK: $w0 = COPY %trunc(s32) + ; CHECK: RET_ReallyLR implicit $w0 + %ptr:_(p0) = COPY $x0 + %int:_(s88) = G_PTRTOINT %ptr + %trunc:_(s32) = G_TRUNC %int + $w0 = COPY %trunc + RET_ReallyLR implicit $w0 +...