diff options
author | Guillaume "Vermeille" Sanchez <guillaumesa@google.com> | 2015-04-20 14:41:30 +0100 |
---|---|---|
committer | Guillaume "Vermeille" Sanchez <guillaumesa@google.com> | 2015-04-23 17:53:17 +0100 |
commit | af88835231c2508509eb19aa2d21b92879351962 (patch) | |
tree | 4ef1c8fb3c5b78175767999a888b0c2cb1ea6485 /compiler/optimizing/code_generator_x86.cc | |
parent | da93333d568f3c5bd8eeb58341d10a332e1d42bf (diff) | |
download | art-af88835231c2508509eb19aa2d21b92879351962.zip art-af88835231c2508509eb19aa2d21b92879351962.tar.gz art-af88835231c2508509eb19aa2d21b92879351962.tar.bz2 |
Remove unnecessary null checks in CheckCast and InstanceOf
Change-Id: I6fd81cabd8673be360f369e6318df0de8b18b634
Diffstat (limited to 'compiler/optimizing/code_generator_x86.cc')
-rw-r--r-- | compiler/optimizing/code_generator_x86.cc | 26 |
1 files changed, 17 insertions, 9 deletions
diff --git a/compiler/optimizing/code_generator_x86.cc b/compiler/optimizing/code_generator_x86.cc index 0cc377c..b48a4d5 100644 --- a/compiler/optimizing/code_generator_x86.cc +++ b/compiler/optimizing/code_generator_x86.cc @@ -4225,9 +4225,11 @@ void InstructionCodeGeneratorX86::VisitInstanceOf(HInstanceOf* instruction) { SlowPathCodeX86* slow_path = nullptr; // Return 0 if `obj` is null. - // TODO: avoid this check if we know obj is not null. - __ testl(obj, obj); - __ j(kEqual, &zero); + // Avoid null check if we know obj is not null. + if (instruction->MustDoNullCheck()) { + __ testl(obj, obj); + __ j(kEqual, &zero); + } __ movl(out, Address(obj, class_offset)); // Compare the class of `obj` with `cls`. if (cls.IsRegister()) { @@ -4252,8 +4254,12 @@ void InstructionCodeGeneratorX86::VisitInstanceOf(HInstanceOf* instruction) { __ movl(out, Immediate(1)); __ jmp(&done); } - __ Bind(&zero); - __ movl(out, Immediate(0)); + + if (instruction->MustDoNullCheck() || instruction->IsClassFinal()) { + __ Bind(&zero); + __ movl(out, Immediate(0)); + } + if (slow_path != nullptr) { __ Bind(slow_path->GetExitLabel()); } @@ -4278,11 +4284,13 @@ void InstructionCodeGeneratorX86::VisitCheckCast(HCheckCast* instruction) { instruction, locations->InAt(1), locations->GetTemp(0), instruction->GetDexPc()); codegen_->AddSlowPath(slow_path); - // TODO: avoid this check if we know obj is not null. - __ testl(obj, obj); - __ j(kEqual, slow_path->GetExitLabel()); - __ movl(temp, Address(obj, class_offset)); + // Avoid null check if we know obj is not null. + if (instruction->MustDoNullCheck()) { + __ testl(obj, obj); + __ j(kEqual, slow_path->GetExitLabel()); + } + __ movl(temp, Address(obj, class_offset)); // Compare the class of `obj` with `cls`. if (cls.IsRegister()) { __ cmpl(temp, cls.AsRegister<Register>()); |