[llvm] 5d6dfba - [ConstExpr] Avoid creation of select constant expressions
Nikita Popov via llvm-commits
llvm-commits at lists.llvm.org
Mon Feb 27 08:10:14 PST 2023
Author: Nikita Popov
Date: 2023-02-27T17:10:05+01:00
New Revision: 5d6dfba1a876456e4ef8e692afa4901b4fa90755
URL: https://github.com/llvm/llvm-project/commit/5d6dfba1a876456e4ef8e692afa4901b4fa90755
DIFF: https://github.com/llvm/llvm-project/commit/5d6dfba1a876456e4ef8e692afa4901b4fa90755.diff
LOG: [ConstExpr] Avoid creation of select constant expressions
These expressions will now only be created if explicitly requested
in IR/bitcode (and by LowerTypeTests, which has a tricky to remove
use).
This is in preparation for removing these expressions entirely,
but also fixes #60983 in the meantime.
Added:
Modified:
llvm/include/llvm/Analysis/TargetFolder.h
llvm/include/llvm/IR/ConstantFolder.h
llvm/lib/Analysis/ConstantFolding.cpp
llvm/test/Transforms/InstCombine/phi-select-constant.ll
Removed:
################################################################################
diff --git a/llvm/include/llvm/Analysis/TargetFolder.h b/llvm/include/llvm/Analysis/TargetFolder.h
index db7eda54b5c45..51f457ddb529a 100644
--- a/llvm/include/llvm/Analysis/TargetFolder.h
+++ b/llvm/include/llvm/Analysis/TargetFolder.h
@@ -133,7 +133,7 @@ class TargetFolder final : public IRBuilderFolder {
auto *TC = dyn_cast<Constant>(True);
auto *FC = dyn_cast<Constant>(False);
if (CC && TC && FC)
- return Fold(ConstantExpr::getSelect(CC, TC, FC));
+ return ConstantFoldSelectInstruction(CC, TC, FC);
return nullptr;
}
diff --git a/llvm/include/llvm/IR/ConstantFolder.h b/llvm/include/llvm/IR/ConstantFolder.h
index 82c07d47a1930..4473187a1bf93 100644
--- a/llvm/include/llvm/IR/ConstantFolder.h
+++ b/llvm/include/llvm/IR/ConstantFolder.h
@@ -123,7 +123,7 @@ class ConstantFolder final : public IRBuilderFolder {
auto *TC = dyn_cast<Constant>(True);
auto *FC = dyn_cast<Constant>(False);
if (CC && TC && FC)
- return ConstantExpr::getSelect(CC, TC, FC);
+ return ConstantFoldSelectInstruction(CC, TC, FC);
return nullptr;
}
diff --git a/llvm/lib/Analysis/ConstantFolding.cpp b/llvm/lib/Analysis/ConstantFolding.cpp
index 585a987c1049a..d6ed643765653 100644
--- a/llvm/lib/Analysis/ConstantFolding.cpp
+++ b/llvm/lib/Analysis/ConstantFolding.cpp
@@ -1083,7 +1083,7 @@ Constant *ConstantFoldInstOperandsImpl(const Value *InstOrCE, unsigned Opcode,
}
return nullptr;
case Instruction::Select:
- return ConstantExpr::getSelect(Ops[0], Ops[1], Ops[2]);
+ return ConstantFoldSelectInstruction(Ops[0], Ops[1], Ops[2]);
case Instruction::ExtractElement:
return ConstantExpr::getExtractElement(Ops[0], Ops[1]);
case Instruction::ExtractValue:
diff --git a/llvm/test/Transforms/InstCombine/phi-select-constant.ll b/llvm/test/Transforms/InstCombine/phi-select-constant.ll
index 15760e2a5b850..1260ef47f65ef 100644
--- a/llvm/test/Transforms/InstCombine/phi-select-constant.ll
+++ b/llvm/test/Transforms/InstCombine/phi-select-constant.ll
@@ -8,9 +8,10 @@ define i32 @foo(i1 %which) {
; CHECK-NEXT: entry:
; CHECK-NEXT: br i1 [[WHICH:%.*]], label [[FINAL:%.*]], label [[DELAY:%.*]]
; CHECK: delay:
+; CHECK-NEXT: [[TMP0:%.*]] = select i1 icmp eq (ptr @A, ptr @B), i32 2, i32 1
; CHECK-NEXT: br label [[FINAL]]
; CHECK: final:
-; CHECK-NEXT: [[USE2:%.*]] = phi i32 [ 1, [[ENTRY:%.*]] ], [ select (i1 icmp eq (ptr @A, ptr @B), i32 2, i32 1), [[DELAY]] ]
+; CHECK-NEXT: [[USE2:%.*]] = phi i32 [ 1, [[ENTRY:%.*]] ], [ [[TMP0]], [[DELAY]] ]
; CHECK-NEXT: ret i32 [[USE2]]
;
entry:
@@ -167,10 +168,10 @@ define i32 @phi_trans(i1 %c, i1 %c2, i32 %v) {
; CHECK: else:
; CHECK-NEXT: [[V3:%.*]] = mul i32 [[V]], 3
; CHECK-NEXT: [[V5:%.*]] = lshr i32 [[V]], 1
-; CHECK-NEXT: [[PHI_SEL:%.*]] = select i1 [[C2:%.*]], i32 [[V3]], i32 [[V5]]
+; CHECK-NEXT: [[TMP0:%.*]] = select i1 [[C2:%.*]], i32 [[V3]], i32 [[V5]]
; CHECK-NEXT: br label [[JOIN]]
; CHECK: join:
-; CHECK-NEXT: [[PHI1:%.*]] = phi i32 [ [[V2]], [[IF]] ], [ [[PHI_SEL]], [[ELSE]] ]
+; CHECK-NEXT: [[PHI1:%.*]] = phi i32 [ [[V2]], [[IF]] ], [ [[TMP0]], [[ELSE]] ]
; CHECK-NEXT: ret i32 [[PHI1]]
;
entry:
More information about the llvm-commits
mailing list