]> granicus.if.org Git - clang/commit
Make clz/ctz builtins defined for zero on ARM targets. rdar://10732455
authorBob Wilson <bob.wilson@apple.com>
Thu, 26 Jan 2012 22:14:27 +0000 (22:14 +0000)
committerBob Wilson <bob.wilson@apple.com>
Thu, 26 Jan 2012 22:14:27 +0000 (22:14 +0000)
commit8b30a9379f730875ba8fb2d0fe2d43611e0c20ff
tree77e52f0858d0eb9a9abef2cb278ace116aab921d
parent66de97fcc368ff7e9ea50337177d007c108cfd73
Make clz/ctz builtins defined for zero on ARM targets.  rdar://10732455

ARM supports clz and ctz directly and both operations have well-defined
results for zero.  There is no disadvantage in performance to using the
defined-at-zero versions of llvm.ctlz/cttz intrinsics.  We're running into
ARM-specific code written with the assumption that __builtin_clz(0) == 32,
even though that value is technically undefined.  The code is failing now
because of llvm optimizations that are taking advantage of the undef
behavior (specifically svn r147255).  There's nothing wrong with that
optimization on x86 where any incorrect assumptions about __builtin_clz(0)
will quickly be exposed.  For ARM, though, optimizations based on that undef
behavior are likely to cause subtle bugs.  Other targets with defined-at-zero
clz/ctz support may want to override the default behavior as well.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@149086 91177308-0d34-0410-b5e6-96231b3b80d8
include/clang/Basic/TargetInfo.h
lib/Basic/Targets.cpp
lib/CodeGen/CGBuiltin.cpp
test/CodeGen/builtin-count-zeros.c