Index: llvm/lib/Target/AArch64/GISel/AArch64LegalizerInfo.cpp =================================================================== --- llvm/lib/Target/AArch64/GISel/AArch64LegalizerInfo.cpp +++ llvm/lib/Target/AArch64/GISel/AArch64LegalizerInfo.cpp @@ -489,9 +489,9 @@ getActionDefinitionsBuilder(G_GLOBAL_VALUE).legalFor({p0}); getActionDefinitionsBuilder(G_PTRTOINT) - .legalForCartesianProduct({s1, s8, s16, s32, s64}, {p0}) - .maxScalar(0, s64) - .widenScalarToNextPow2(0, /*Min*/ 8); + .legalFor({{s64, p0}}) + .widenScalarToNextPow2(0, 64) + .clampScalar(0, s64, s64); getActionDefinitionsBuilder(G_INTTOPTR) .unsupportedIf([&](const LegalityQuery &Query) { Index: llvm/test/CodeGen/AArch64/GlobalISel/legalize-exceptions.ll =================================================================== --- llvm/test/CodeGen/AArch64/GlobalISel/legalize-exceptions.ll +++ llvm/test/CodeGen/AArch64/GlobalISel/legalize-exceptions.ll @@ -1,3 +1,4 @@ +; NOTE: Assertions have been autogenerated by utils/update_mir_test_checks.py ; RUN: llc -O0 -mtriple=aarch64-apple-ios -verify-machineinstrs -global-isel -stop-after=legalizer %s -o - | FileCheck %s @_ZTIi = external global i8* @@ -7,21 +8,39 @@ declare i32 @llvm.eh.typeid.for(i8*) declare void @_Unwind_Resume(i8*) -; CHECK: name: bar -; CHECK: body: -; CHECK-NEXT: bb.1 (%ir-block.0): -; CHECK: successors: %{{bb.[0-9]+.*}}%[[LP:bb.[0-9]+]] - -; CHECK: [[LP]].{{[a-z]+}} (landing-pad): -; CHECK: EH_LABEL - -; CHECK: [[PTR:%[0-9]+]]:_(p0) = COPY $x0 -; CHECK: [[SEL_PTR:%[0-9]+]]:_(p0) = COPY $x1 -; CHECK: [[SEL_PTR_INT:%[0-9]+]]:_(s32) = G_PTRTOINT [[SEL_PTR]](p0) -; CHECK: G_STORE [[PTR]](p0), %0(p0) :: (store (p0) into %ir.exn.slot) -; CHECK: G_STORE [[SEL_PTR_INT]](s32), %1(p0) :: (store (s32) into %ir.ehselector.slot) - define void @bar() personality i8* bitcast (i32 (...)* @__gxx_personality_v0 to i8*) { + ; CHECK-LABEL: name: bar + ; CHECK: bb.1 (%ir-block.0): + ; CHECK: successors: %bb.3(0x40000000), %bb.2(0x40000000) + ; CHECK: [[C:%[0-9]+]]:_(s32) = G_CONSTANT i32 42 + ; CHECK: [[FRAME_INDEX:%[0-9]+]]:_(p0) = G_FRAME_INDEX %stack.0.exn.slot + ; CHECK: [[FRAME_INDEX1:%[0-9]+]]:_(p0) = G_FRAME_INDEX %stack.1.ehselector.slot + ; CHECK: EH_LABEL + ; CHECK: ADJCALLSTACKDOWN 0, 0, implicit-def $sp, implicit $sp + ; CHECK: $w0 = COPY [[C]](s32) + ; CHECK: BL @foo, csr_darwin_aarch64_aapcs, implicit-def $lr, implicit $sp, implicit $w0, implicit-def $w0 + ; CHECK: ADJCALLSTACKUP 0, 0, implicit-def $sp, implicit $sp + ; CHECK: EH_LABEL + ; CHECK: G_BR %bb.3 + ; CHECK: bb.2.cleanup (landing-pad): + ; CHECK: successors: %bb.4(0x80000000) + ; CHECK: liveins: $x0, $x1 + ; CHECK: EH_LABEL + ; CHECK: [[COPY:%[0-9]+]]:_(p0) = COPY $x0 + ; CHECK: [[COPY1:%[0-9]+]]:_(p0) = COPY $x1 + ; CHECK: [[PTRTOINT:%[0-9]+]]:_(s64) = G_PTRTOINT [[COPY1]](p0) + ; CHECK: [[TRUNC:%[0-9]+]]:_(s32) = G_TRUNC [[PTRTOINT]](s64) + ; CHECK: G_STORE [[COPY]](p0), [[FRAME_INDEX]](p0) :: (store (p0) into %ir.exn.slot) + ; CHECK: G_STORE [[TRUNC]](s32), [[FRAME_INDEX1]](p0) :: (store (s32) into %ir.ehselector.slot) + ; CHECK: G_BR %bb.4 + ; CHECK: bb.3.continue: + ; CHECK: RET_ReallyLR + ; CHECK: bb.4.eh.resume: + ; CHECK: [[LOAD:%[0-9]+]]:_(p0) = G_LOAD [[FRAME_INDEX]](p0) :: (dereferenceable load (p0) from %ir.exn.slot) + ; CHECK: ADJCALLSTACKDOWN 0, 0, implicit-def $sp, implicit $sp + ; CHECK: $x0 = COPY [[LOAD]](p0) + ; CHECK: BL @_Unwind_Resume, csr_darwin_aarch64_aapcs, implicit-def $lr, implicit $sp, implicit $x0 + ; CHECK: ADJCALLSTACKUP 0, 0, implicit-def $sp, implicit $sp %exn.slot = alloca i8* %ehselector.slot = alloca i32 %1 = invoke i32 @foo(i32 42) to label %continue unwind label %cleanup Index: llvm/test/CodeGen/AArch64/GlobalISel/legalize-ptrtoint.mir =================================================================== --- /dev/null +++ llvm/test/CodeGen/AArch64/GlobalISel/legalize-ptrtoint.mir @@ -0,0 +1,121 @@ +# 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: [[PTRTOINT:%[0-9]+]]:_(s64) = G_PTRTOINT %ptr(p0) + ; CHECK: %int:_(s32) = G_TRUNC [[PTRTOINT]](s64) + ; 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: [[PTRTOINT:%[0-9]+]]:_(s64) = G_PTRTOINT %ptr(p0) + ; CHECK: %int:_(s16) = G_TRUNC [[PTRTOINT]](s64) + ; 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: [[PTRTOINT:%[0-9]+]]:_(s64) = G_PTRTOINT %ptr(p0) + ; CHECK: %int:_(s8) = G_TRUNC [[PTRTOINT]](s64) + ; 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: [[PTRTOINT:%[0-9]+]]:_(s64) = G_PTRTOINT %ptr(p0) + ; CHECK: [[C:%[0-9]+]]:_(s32) = G_CONSTANT i32 1 + ; CHECK: [[TRUNC:%[0-9]+]]:_(s32) = G_TRUNC [[PTRTOINT]](s64) + ; CHECK: %ext:_(s32) = G_AND [[TRUNC]], [[C]] + ; 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 +... Index: llvm/test/CodeGen/AArch64/GlobalISel/select-int-ptr-casts.mir =================================================================== --- llvm/test/CodeGen/AArch64/GlobalISel/select-int-ptr-casts.mir +++ llvm/test/CodeGen/AArch64/GlobalISel/select-int-ptr-casts.mir @@ -63,12 +63,16 @@ bb.0: liveins: $x0 ; CHECK-LABEL: name: ptrtoint_s32_p0 - ; CHECK: [[COPY:%[0-9]+]]:gpr64 = COPY $x0 - ; CHECK: [[COPY1:%[0-9]+]]:gpr32 = COPY [[COPY]].sub_32 - ; CHECK: $w0 = COPY [[COPY1]] - %0(p0) = COPY $x0 - %1(s32) = G_PTRTOINT %0 - $w0 = COPY %1(s32) + ; CHECK: %ptr:gpr64 = COPY $x0 + ; CHECK: %ptr2int:gpr64common = COPY %ptr + ; CHECK: %int:gpr32sp = COPY %ptr2int.sub_32 + ; CHECK: $w0 = COPY %int + ; CHECK: RET_ReallyLR implicit $w0 + %ptr:gpr(p0) = COPY $x0 + %ptr2int:gpr(s64) = G_PTRTOINT %ptr(p0) + %int:gpr(s32) = G_TRUNC %ptr2int(s64) + $w0 = COPY %int(s32) + RET_ReallyLR implicit $w0 ... --- @@ -83,14 +87,17 @@ bb.0: liveins: $x0 ; CHECK-LABEL: name: ptrtoint_s16_p0 - ; CHECK: [[COPY:%[0-9]+]]:gpr64 = COPY $x0 - ; CHECK: [[COPY1:%[0-9]+]]:gpr32 = COPY [[COPY]].sub_32 - ; CHECK: [[COPY2:%[0-9]+]]:gpr32all = COPY [[COPY1]] - ; CHECK: $w0 = COPY [[COPY2]] - %0(p0) = COPY $x0 - %1(s16) = G_PTRTOINT %0 - %2:gpr(s32) = G_ANYEXT %1 - $w0 = COPY %2(s32) + ; CHECK: %ptr:gpr64 = COPY $x0 + ; CHECK: %int:gpr32 = COPY %ptr.sub_32 + ; CHECK: [[COPY:%[0-9]+]]:fpr32 = COPY %int + ; CHECK: [[COPY1:%[0-9]+]]:fpr16 = COPY [[COPY]].hsub + ; CHECK: $h0 = COPY [[COPY1]] + ; CHECK: RET_ReallyLR implicit $h0 + %ptr:gpr(p0) = COPY $x0 + %ptr2int:gpr(s64) = G_PTRTOINT %ptr(p0) + %int:gpr(s16) = G_TRUNC %ptr2int(s64) + $h0 = COPY %int(s16) + RET_ReallyLR implicit $h0 ... --- @@ -105,14 +112,17 @@ bb.0: liveins: $x0 ; CHECK-LABEL: name: ptrtoint_s8_p0 - ; CHECK: [[COPY:%[0-9]+]]:gpr64 = COPY $x0 - ; CHECK: [[COPY1:%[0-9]+]]:gpr32 = COPY [[COPY]].sub_32 - ; CHECK: [[COPY2:%[0-9]+]]:gpr32all = COPY [[COPY1]] - ; CHECK: $w0 = COPY [[COPY2]] - %0(p0) = COPY $x0 - %1(s8) = G_PTRTOINT %0 - %2:gpr(s32) = G_ANYEXT %1 - $w0 = COPY %2(s32) + ; CHECK: %ptr:gpr64 = COPY $x0 + ; CHECK: %int:gpr32 = COPY %ptr.sub_32 + ; CHECK: [[COPY:%[0-9]+]]:fpr32 = COPY %int + ; CHECK: [[COPY1:%[0-9]+]]:fpr8 = COPY [[COPY]].bsub + ; CHECK: $b0 = COPY [[COPY1]] + ; CHECK: RET_ReallyLR implicit $b0 + %ptr:gpr(p0) = COPY $x0 + %ptr2int:gpr(s64) = G_PTRTOINT %ptr(p0) + %int:gpr(s8) = G_TRUNC %ptr2int(s64) + $b0 = COPY %int(s8) + RET_ReallyLR implicit $b0 ... --- @@ -127,14 +137,19 @@ bb.0: liveins: $x0 ; CHECK-LABEL: name: ptrtoint_s1_p0 - ; CHECK: [[COPY:%[0-9]+]]:gpr64 = COPY $x0 - ; CHECK: [[COPY1:%[0-9]+]]:gpr32 = COPY [[COPY]].sub_32 - ; CHECK: [[COPY2:%[0-9]+]]:gpr32all = COPY [[COPY1]] - ; CHECK: $w0 = COPY [[COPY2]] - %0(p0) = COPY $x0 - %1(s1) = G_PTRTOINT %0 - %2:gpr(s32) = G_ANYEXT %1 - $w0 = COPY %2(s32) + ; CHECK: %ptr:gpr64 = COPY $x0 + ; CHECK: %ptr2int:gpr64common = COPY %ptr + ; CHECK: %trunc:gpr32common = COPY %ptr2int.sub_32 + ; CHECK: %ext:gpr32sp = ANDWri %trunc, 0 + ; CHECK: $w0 = COPY %ext + ; CHECK: RET_ReallyLR implicit $w0 + %ptr:gpr(p0) = COPY $x0 + %ptr2int:gpr(s64) = G_PTRTOINT %ptr(p0) + %one:gpr(s32) = G_CONSTANT i32 1 + %trunc:gpr(s32) = G_TRUNC %ptr2int(s64) + %ext:gpr(s32) = G_AND %trunc, %one + $w0 = COPY %ext(s32) + RET_ReallyLR implicit $w0 ... ---