https://bugs.llvm.org/show_bug.cgi?id=35909
Bug ID: 35909
Summary: static_cast<T*>(this) does not propagate non-null
invariant of 'this'
Product: clang
Version: trunk
Hardware: All
OS: All
Status: NEW
Severity: enhancement
Priority: P
Component: -New Bugs
Assignee: unassignedclangb...@nondot.org
Reporter: d...@znu.io
CC: llvm-bugs@lists.llvm.org
static_cast<T*>(this) does not propagate non-null invariant of 'this'.
Consider the following code (found during code gen analysis of a LLVM
subproject):
class A {
int a;
};
class B {
int b;
public:
A *getAsA();
};
class X : public A, public B {
int x;
};
A *B::getAsA() {
if (b == 42) {
auto temp = static_cast<X*>(this);
//__builtin_assume(temp != nullptr);
return temp;
}
return nullptr;
}
void helper(A *);
void test(B *b) {
auto temp = b->getAsA();
if (temp)
return helper(temp);
}
WITHOUT the __builtin_assume(), the following suboptimal x86 code is generated:
movq %rdi, %rax
addq $-4, %rdi
je .LBB1_2
cmpl $42, (%rax)
jne .LBB1_2
jmp _Z6helperP1A # TAILCALL
.LBB1_2:
retq
WITH the __builtin_assume(), the following optimal x86 code is generated:
cmpl $42, (%rdi)
jne .LBB1_1
addq $-4, %rdi
jmp _Z6helperP1A # TAILCALL
.LBB1_1:
retq
--
You are receiving this mail because:
You are on the CC list for the bug.
_______________________________________________
llvm-bugs mailing list
llvm-bugs@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-bugs