Skip to content

Commit

Permalink
Fix return type of LongBinaryOp<Power>
Browse files Browse the repository at this point in the history
Summary:
It will return a float when the exponent is negative.  Caught when running tests
with AutoJIT + type profiling.

I don't see other instances of `Float | Long` types in HIR anywhere yet, but it
appears to work fine.

Reviewed By: mpage, swtaarrs

Differential Revision: D50091025

fbshipit-source-id: 77ad3b50a48da9c28bf43f776a163c88e068d8f3
  • Loading branch information
Alex Malyshev authored and facebook-github-bot committed Oct 10, 2023
1 parent 769fcb5 commit a69bb4d
Show file tree
Hide file tree
Showing 2 changed files with 73 additions and 0 deletions.
4 changes: 4 additions & 0 deletions Jit/hir/ssa.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -517,6 +517,10 @@ Type outputType(
if (binop.op() == BinaryOpKind::kTrueDivide) {
return TFloatExact;
}
if (binop.op() == BinaryOpKind::kPower) {
// Will be floating-point for negative exponents.
return TFloatExact | TLongExact;
}
return TLongExact;
}
case Opcode::kLongCompare:
Expand Down
69 changes: 69 additions & 0 deletions RuntimeTests/hir_tests/profile_data_hir_test.txt
Original file line number Diff line number Diff line change
Expand Up @@ -308,6 +308,75 @@ fun jittestmodule:test {
}
}
---
SpecializePowerHasCorrectType
---
class Point:
def __init__(self, x, y):
self.x = x
self.y = y

__slots__ = ("x", "y")

def test(p):
return p.x ** p.y

test(Point(1, -2))
---
fun jittestmodule:test {
bb 0 {
v4:Object = LoadArg<0; "p">
Snapshot
v6:ObjectUser[Point:Exact] = GuardType<ObjectUser[Point:Exact]> v4 {
GuiltyReg v4
}
DeoptPatchpoint<0xdeadbeef> {
Descr 'member descriptor attribute'
GuiltyReg v6
}
UseType<ObjectUser[Point:Exact]> v6
v14:OptObject = LoadField<x@16, OptObject, borrowed> v6
v15:Object = CheckField<"x"> v14 {
GuiltyReg v6
FrameState {
NextInstrOffset 4
Locals<1> v6
}
}
Snapshot
DeoptPatchpoint<0xdeadbeef> {
Descr 'member descriptor attribute'
GuiltyReg v6
}
UseType<ObjectUser[Point:Exact]> v6
v16:OptObject = LoadField<y@24, OptObject, borrowed> v6
v17:Object = CheckField<"y"> v16 {
GuiltyReg v6
FrameState {
NextInstrOffset 8
Locals<1> v6
Stack<1> v15
}
}
Snapshot
v11:LongExact = GuardType<LongExact> v15 {
GuiltyReg v15
}
v12:LongExact = GuardType<LongExact> v17 {
GuiltyReg v17
}
UseType<LongExact> v11
UseType<LongExact> v12
v18:{FloatExact|LongExact} = LongBinaryOp<Power> v11 v12 {
FrameState {
NextInstrOffset 10
Locals<1> v6
}
}
Snapshot
Return v18
}
}
---
SpecializeSplitDictLoadAttr
---
class Person:
Expand Down

0 comments on commit a69bb4d

Please sign in to comment.