llvm.org GIT mirror llvm / 0e488b3
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. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@96816 91177308-0d34-0410-b5e6-96231b3b80d8 Dan Gohman 10 years ago
3 changed file(s) with 7 addition(s) and 3 deletion(s). Raw diff Collapse all Expand all
793793 // it is casted back to a pointer, see if the expression can be
794794 // converted into a GEP.
795795 if (CE->getOpcode() == Instruction::Add)
796 if (ConstantInt *L = dyn_cast(CE->getOperand(0)))
797 if (ConstantExpr *R = dyn_cast>(CE->getOperand(1)))
796 if (ConstantInt *L = dyn_cast>(CE->getOperand(1)))
797 if (ConstantExpr *R = dyn_cast(CE->getOperand(0)))
798798 if (R->getOpcode() == Instruction::PtrToInt)
799799 if (GlobalVariable *GV =
800800 dyn_cast(R->getOperand(0))) {
11041104 return ConstantExpr::getLShr(C1, C2);
11051105 break;
11061106 }
1107 } else if (isa(C1)) {
1108 // If C1 is a ConstantInt and C2 is not, swap the operands.
1109 if (Instruction::isCommutative(Opcode))
1110 return ConstantExpr::get(Opcode, C2, C1);
11071111 }
11081112
11091113 // At this point we know neither constant is an UndefValue.
88
99 ; CHECK: .globl x
1010 ; CHECK: x:
11 ; CHECK: .quad 3
11 ; CHECK: .quad ((0+1)&4294967295)*3
1212
1313 @x = global i64 mul (i64 3, i64 ptrtoint (i2* getelementptr (i2* null, i64 1) to i64))