[llvm-commits] [llvm] r96816 - in /llvm/trunk: lib/Analysis/ConstantFolding.cpp lib/VMCore/ConstantFold.cpp test/CodeGen/X86/ptrtoint-constexpr.ll
Dan Gohman
gohman at apple.com
Mon Feb 22 14:43:24 PST 2010
Author: djg
Date: Mon Feb 22 16:43:23 2010
New Revision: 96816
URL: http://llvm.org/viewvc/llvm-project?rev=96816&view=rev
Log:
Canonicalize ConstantInts to the right operand of commutative
operators.
The test difference is just due to the multiplication operands
being commuted (and thus requiring a more elaborate match). In
optimized code, that expression would be folded.
Modified:
llvm/trunk/lib/Analysis/ConstantFolding.cpp
llvm/trunk/lib/VMCore/ConstantFold.cpp
llvm/trunk/test/CodeGen/X86/ptrtoint-constexpr.ll
Modified: llvm/trunk/lib/Analysis/ConstantFolding.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Analysis/ConstantFolding.cpp?rev=96816&r1=96815&r2=96816&view=diff
==============================================================================
--- llvm/trunk/lib/Analysis/ConstantFolding.cpp (original)
+++ llvm/trunk/lib/Analysis/ConstantFolding.cpp Mon Feb 22 16:43:23 2010
@@ -794,8 +794,8 @@
// it is casted back to a pointer, see if the expression can be
// converted into a GEP.
if (CE->getOpcode() == Instruction::Add)
- if (ConstantInt *L = dyn_cast<ConstantInt>(CE->getOperand(0)))
- if (ConstantExpr *R = dyn_cast<ConstantExpr>(CE->getOperand(1)))
+ if (ConstantInt *L = dyn_cast<ConstantInt>(CE->getOperand(1)))
+ if (ConstantExpr *R = dyn_cast<ConstantExpr>(CE->getOperand(0)))
if (R->getOpcode() == Instruction::PtrToInt)
if (GlobalVariable *GV =
dyn_cast<GlobalVariable>(R->getOperand(0))) {
Modified: llvm/trunk/lib/VMCore/ConstantFold.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/VMCore/ConstantFold.cpp?rev=96816&r1=96815&r2=96816&view=diff
==============================================================================
--- llvm/trunk/lib/VMCore/ConstantFold.cpp (original)
+++ llvm/trunk/lib/VMCore/ConstantFold.cpp Mon Feb 22 16:43:23 2010
@@ -1105,6 +1105,10 @@
return ConstantExpr::getLShr(C1, C2);
break;
}
+ } else if (isa<ConstantInt>(C1)) {
+ // If C1 is a ConstantInt and C2 is not, swap the operands.
+ if (Instruction::isCommutative(Opcode))
+ return ConstantExpr::get(Opcode, C2, C1);
}
// At this point we know neither constant is an UndefValue.
Modified: llvm/trunk/test/CodeGen/X86/ptrtoint-constexpr.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/CodeGen/X86/ptrtoint-constexpr.ll?rev=96816&r1=96815&r2=96816&view=diff
==============================================================================
--- llvm/trunk/test/CodeGen/X86/ptrtoint-constexpr.ll (original)
+++ llvm/trunk/test/CodeGen/X86/ptrtoint-constexpr.ll Mon Feb 22 16:43:23 2010
@@ -9,6 +9,6 @@
; CHECK: .globl x
; CHECK: x:
-; CHECK: .quad 3
+; CHECK: .quad ((0+1)&4294967295)*3
@x = global i64 mul (i64 3, i64 ptrtoint (i2* getelementptr (i2* null, i64 1) to i64))
More information about the llvm-commits
mailing list