[llvm-commits] CAST patch: #4 the rest, except instcombine
Chris Lattner
clattner at apple.com
Mon Nov 20 15:10:59 PST 2006
On Nov 18, 2006, at 11:24 AM, Reid Spencer wrote:
> Chris,
>
> Here's the CAST patch. This passes 100% of llvm/test and llvm-test.
> The
> order of the files in the patch has been set up for logical review.
> Some
> of this you've already seen, but its changed so much that those things
> should probably be reviewed again.
Please verify that CBE handles truncate to bool correctly. It
probably needs
something like this:
(_Bool)(X & 1)
not:
(_Bool)X
Likewise, sext from bool should also be checked, it should compile to
(destty)(0-bool).
Index: lib/CodeGen/AsmPrinter.cpp
===================================================================
RCS file: /var/cvs/llvm/llvm/lib/CodeGen/AsmPrinter.cpp,v
retrieving revision 1.116
diff -t -d -u -p -5 -r1.116 AsmPrinter.cpp
--- lib/CodeGen/AsmPrinter.cpp 1 Nov 2006 09:23:08 -0000 1.116
+++ lib/CodeGen/AsmPrinter.cpp 18 Nov 2006 19:22:22 -0000
@@ -413,11 +413,25 @@ void AsmPrinter::EmitConstantValueOnly(c
} else {
EmitConstantValueOnly(ptrVal);
}
break;
}
- case Instruction::Cast: {
+ case Instruction::Trunc:
+ case Instruction::ZExt:
+ case Instruction::SExt:
+ case Instruction::FPTrunc:
+ case Instruction::FPExt:
+ case Instruction::UIToFP:
+ case Instruction::SIToFP:
+ case Instruction::FPToUI:
+ case Instruction::FPToSI:
+ assert(0 && "FIXME: Don't yet support this kind of constant
cast expr");
+ EmitConstantValueOnly(CE->getOperand(0));
+ break;
Why not remove the code after the assert?
===================================================================
RCS file: /var/cvs/llvm/llvm/lib/CodeGen/MachineDebugInfo.cpp,v
retrieving revision 1.59
diff -t -d -u -p -5 -r1.59 MachineDebugInfo.cpp
--- lib/CodeGen/MachineDebugInfo.cpp 8 Nov 2006 14:17:45 -0000 1.59
+++ lib/CodeGen/MachineDebugInfo.cpp 18 Nov 2006 19:22:23 -0000
@@ -100,11 +100,11 @@ static bool isStringValue(Value *V) {
///
static GlobalVariable *getGlobalVariable(Value *V) {
if (GlobalVariable *GV = dyn_cast<GlobalVariable>(V)) {
return GV;
} else if (ConstantExpr *CE = dyn_cast<ConstantExpr>(V)) {
- if (CE->getOpcode() == Instruction::Cast) {
+ if (CE->isCast()) {
return dyn_cast<GlobalVariable>(CE->getOperand(0));
}
}
return NULL;
}
@@ -113,11 +113,11 @@ static GlobalVariable *getGlobalVariable
/// GlobalVariable.
static bool isGlobalVariable(Value *V) {
if (isa<GlobalVariable>(V) || isa<ConstantPointerNull>(V)) {
return true;
} else if (ConstantExpr *CE = dyn_cast<ConstantExpr>(V)) {
- if (CE->getOpcode() == Instruction::Cast) {
+ if (CE->isCast()) {
return isa<GlobalVariable>(CE->getOperand(0));
}
}
return false;
}
These should just check bitcast.
--- lib/CodeGen/SelectionDAG/SelectionDAGISel.cpp 15 Nov 2006
17:51:15 -0000 1.318
+++ lib/CodeGen/SelectionDAG/SelectionDAGISel.cpp 18 Nov 2006
19:22:25 -0000
@@ -3344,11 +3418,11 @@ static bool OptimizeNoopCopyExpression(C
if (!InsertedCast) {
BasicBlock::iterator InsertPt = UserBB->begin();
while (isa<PHINode>(InsertPt)) ++InsertPt;
InsertedCast =
- new CastInst(CI->getOperand(0), CI->getType(), "", InsertPt);
+ CastInst::getCast(CI->getOperand(0), CI->getType(), "",
InsertPt);
MadeChange = true;
}
This can just be bitcast.
@@ -3382,15 +3456,15 @@ static Instruction *InsertGEPComputeCode
// Add the offset, cast it to the right type.
Ptr = BinaryOperator::createAdd(Ptr, PtrOffset, "", InsertPt);
- return V = new CastInst(Ptr, GEPI->getType(), "", InsertPt);
+ return V = CastInst::getCast(Ptr, GEPI->getType(), "", InsertPt);
}
This should always be inttoptr.
@@ -3403,12 +3477,13 @@ static void ReplaceUsesOfGEPInst(Instruc
GetElementPtrInst *GEPI,
std::map<BasicBlock*,Instruction*>
&InsertedExprs) {
while (!RepPtr->use_empty()) {
Instruction *User = cast<Instruction>(RepPtr->use_back());
- // If the user is a Pointer-Pointer cast, recurse.
- if (isa<CastInst>(User) && isa<PointerType>(User->getType())) {
+ // If the user is a Pointer-Pointer cast, recurse. Only BitCast
can be
+ // used for a Pointer-Pointer cast.
+ if (isa<BitCastInst>(User) && isa<PointerType>(User->getType())) {
ReplaceUsesOfGEPInst(User, Ptr, PtrOffset, DefBB, GEPI,
InsertedExprs);
// Drop the use of RepPtr. The cast is dead. Don't delete it
now, else we
// could invalidate an iterator.
User->setOperand(0, UndefValue::get(RepPtr->getType()));
No need to check isa<PointerType> in the if.
===================================================================
RCS file: /var/cvs/llvm/llvm/test/Regression/Transforms/InstCombine/
call-cast-target.ll,v
retrieving revision 1.1
diff -t -d -u -p -5 -r1.1 call-cast-target.ll
--- test/Regression/Transforms/InstCombine/call-cast-target.ll 20 Apr
2006 14:54:17 -0000 1.1
+++ test/Regression/Transforms/InstCombine/call-cast-target.ll 18 Nov
2006 19:22:28 -0000
@@ -1,6 +1,6 @@
-; RUN: llvm-as < %s | opt -instcombine | llvm-dis | grep call | not
grep cast
+; RUN: llvm-as < %s | opt -instcombine | llvm-dis | grep call | not
grep bitconvert
'not grep bitcast'
likewise in other testcases.
Index: test/Regression/Transforms/InstCombine/cast-malloc.ll
===================================================================
RCS file: test/Regression/Transforms/InstCombine/cast-malloc.ll
diff -N test/Regression/Transforms/InstCombine/cast-malloc.ll
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ test/Regression/Transforms/InstCombine/cast-malloc.ll 18 Nov 2006
19:22:28 -0000
@@ -0,0 +1,8 @@
+; test that casted mallocs get converted to malloc of the right type
+; RUN: llvm-as < %s | opt -instcombine | llvm-dis | not grep bitconvert
+
+int* %test(uint %size) {
+ %X = malloc long, uint %size
+ %ret = bitconvert long* %X to int*
+ ret int* %ret
+}
s/bitconvert/bitcast (two places)
Index: test/Regression/Transforms/InstCombine/getelementptr_cast.ll
===================================================================
RCS file: /var/cvs/llvm/llvm/test/Regression/Transforms/InstCombine/
getelementptr_cast.ll,v
retrieving revision 1.1
diff -t -d -u -p -5 -r1.1 getelementptr_cast.ll
--- test/Regression/Transforms/InstCombine/getelementptr_cast.ll 27
Nov 2004 17:55:20 -0000 1.1
+++ test/Regression/Transforms/InstCombine/getelementptr_cast.ll 18
Nov 2006 19:22:29 -0000
@@ -1,9 +1,9 @@
-; RUN: llvm-as < %s | opt -instcombine | llvm-dis | not grep
'getelementptr.*cast'
+; RUN: llvm-as < %s | opt -instcombine | llvm-dis | notcast ''
'getelementptr.*'
%G = external global [3 x sbyte]
notcast takes an argument?
--- test/Regression/Transforms/LevelRaise/2002-05-10-LoadPeephole.ll
16 Sep 2003 15:29:36 -0000 1.3
+++ test/Regression/Transforms/LevelRaise/2002-05-10-LoadPeephole.ll
18 Nov 2006 19:22:29 -0000
@@ -1,9 +1,9 @@
; This testcase should have the cast propogated through the load
; just like a store does...
;
-; RUN: llvm-as < %s | opt -raise | llvm-dis | grep ' cast ' | not
grep '*'
+; RUN: llvm-as < %s | opt -raise | llvm-dis | not grep 'bitconvert
uint \*'
bad run line
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20061120/b8dfc312/attachment.html>
More information about the llvm-commits
mailing list