[llvm-commits] [llvm-gcc-4.2] r57078 - /llvm-gcc-4.2/trunk/gcc/llvm-convert.cpp
Chris Lattner
sabre at nondot.org
Sat Oct 4 15:26:03 PDT 2008
Author: lattner
Date: Sat Oct 4 17:26:02 2008
New Revision: 57078
URL: http://llvm.org/viewvc/llvm-project?rev=57078&view=rev
Log:
optimize a very very common case for -O0. We usually get a COND_EXPR with a
comparison as an operand. Calling 'Emit' on the operand emits the icmp/fcmp,
but then zext's the result out to sizeof(bool). This compiles:
if (X < 4) {
into llvm IR like this:
%1 = icmp sle i32 %0, 3 ; <i1> [#uses=1]
%2 = zext i1 %1 to i8 ; <i8> [#uses=1]
%toBool = icmp ne i8 %2, 0 ; <i1> [#uses=1]
br i1 %toBool, label %bb, label %bb3
Change llvm-convert to avoid inserting the 'toBool' icmp in this case, we
now produce (note that the branch directly uses the icmp):
%1 = icmp sle i32 %0, 3 ; <i1> [#uses=2]
%2 = zext i1 %1 to i8 ; <i8> [#uses=0]
br i1 %1, label %bb, label %bb2
None of this really matters at -O, but at -O0 with fastisel, this doesn't get
optimized away. fastisel is still producing ugly code due to the dead
zext though, stay tuned.
Modified:
llvm-gcc-4.2/trunk/gcc/llvm-convert.cpp
Modified: llvm-gcc-4.2/trunk/gcc/llvm-convert.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm-gcc-4.2/trunk/gcc/llvm-convert.cpp?rev=57078&r1=57077&r2=57078&view=diff
==============================================================================
--- llvm-gcc-4.2/trunk/gcc/llvm-convert.cpp (original)
+++ llvm-gcc-4.2/trunk/gcc/llvm-convert.cpp Sat Oct 4 17:26:02 2008
@@ -1817,9 +1817,18 @@
// Emit the conditional expression.
Value *Cond = Emit(COND_EXPR_COND(exp), 0);
// If its not already a bool, insert a comparison against zero to make it so.
- if (Cond->getType() != Type::Int1Ty)
- Cond = Builder.CreateICmpNE(Cond, Constant::getNullValue(Cond->getType()),
- "toBool");
+ if (Cond->getType() != Type::Int1Ty) {
+ // Handle the common case where a boolean expression was evaluated as our
+ // operand, but was then zero extended to a larger integer type. At -O0, we
+ // don't really want to emit "a = icmp...; b = zext a to i8; c = icmp b, 0"
+ if (ZExtInst *CondI = dyn_cast<ZExtInst>(Cond))
+ if (CondI->getOperand(0)->getType() == Type::Int1Ty)
+ Cond = CondI->getOperand(0);
+
+ // Otherwise, emit a simple comparison.
+ if (Cond->getType() != Type::Int1Ty)
+ Cond = Builder.CreateIsNotNull(Cond, "toBool");
+ }
tree Then = COND_EXPR_THEN(exp);
tree Else = COND_EXPR_ELSE(exp);
More information about the llvm-commits
mailing list