Skip to content

Commit b7baf2e

Browse files
committed
[IR] Mark mul constant expression as undesirable
This is a (very belated) reland of 0a362f1, which I originally reverted due to flang test failures. This marks mul constant expressions as undesirable, which means that we will no longer create them by default, but they can still be created explicitly. Part of: https://discourse.llvm.org/t/rfc-remove-most-constant-expressions/63179
1 parent 308ce8d commit b7baf2e

File tree

3 files changed

+4
-3
lines changed

3 files changed

+4
-3
lines changed

llvm/lib/IR/Constants.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2395,10 +2395,10 @@ bool ConstantExpr::isDesirableBinOp(unsigned Opcode) {
23952395
case Instruction::LShr:
23962396
case Instruction::AShr:
23972397
case Instruction::Shl:
2398+
case Instruction::Mul:
23982399
return false;
23992400
case Instruction::Add:
24002401
case Instruction::Sub:
2401-
case Instruction::Mul:
24022402
case Instruction::Xor:
24032403
return true;
24042404
default:

llvm/test/Transforms/InstCombine/add2.ll

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -325,7 +325,8 @@ define i16 @mul_add_to_mul_9(i16 %a) {
325325

326326
define i32 @shl_add_to_shl_constexpr() {
327327
; CHECK-LABEL: @shl_add_to_shl_constexpr(
328-
; CHECK-NEXT: ret i32 mul (i32 ptrtoint (ptr @g to i32), i32 4)
328+
; CHECK-NEXT: [[ADD:%.*]] = shl i32 ptrtoint (ptr @g to i32), 2
329+
; CHECK-NEXT: ret i32 [[ADD]]
329330
;
330331
%shl = shl i32 ptrtoint (ptr @g to i32), 1
331332
%add = add i32 %shl, %shl

llvm/test/Transforms/NewGVN/2009-11-12-MemDepMallocBitCast.ll

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55

66
define i64 @test() {
77
; CHECK-LABEL: define i64 @test() {
8-
; CHECK-NEXT: [[TMP1:%.*]] = tail call ptr @malloc(i64 mul (i64 ptrtoint (ptr getelementptr (i64, ptr null, i64 1) to i64), i64 4))
8+
; CHECK-NEXT: [[TMP1:%.*]] = tail call ptr @malloc(i64 mul (i64 4, i64 ptrtoint (ptr getelementptr (i64, ptr null, i64 1) to i64)))
99
; CHECK-NEXT: store i8 42, ptr [[TMP1]], align 1
1010
; CHECK-NEXT: [[Y:%.*]] = load i64, ptr [[TMP1]], align 4
1111
; CHECK-NEXT: ret i64 [[Y]]

0 commit comments

Comments
 (0)