[llvm] ed47a9c - [Attributor][FIX] Handle the default case of a switch
Johannes Doerfert via llvm-commits
llvm-commits at lists.llvm.org
Fri Nov 1 22:31:35 PDT 2019
Author: Johannes Doerfert
Date: 2019-11-02T00:30:31-05:00
New Revision: ed47a9cde4f667058ac34ef7805fc4093a5a4f7b
URL: https://github.com/llvm/llvm-project/commit/ed47a9cde4f667058ac34ef7805fc4093a5a4f7b
DIFF: https://github.com/llvm/llvm-project/commit/ed47a9cde4f667058ac34ef7805fc4093a5a4f7b.diff
LOG: [Attributor][FIX] Handle the default case of a switch
In D69605 only the "cases" of a switch were handled but if none matched
we did not make the default case life. This is fixed now and properly
tested (with code from IPConstantProp/user-with-multiple-uses.ll).
Added:
Modified:
llvm/lib/Transforms/IPO/Attributor.cpp
llvm/test/Transforms/FunctionAttrs/liveness.ll
Removed:
################################################################################
diff --git a/llvm/lib/Transforms/IPO/Attributor.cpp b/llvm/lib/Transforms/IPO/Attributor.cpp
index 9fdfed8dbedb..3d6a2c6f94f6 100644
--- a/llvm/lib/Transforms/IPO/Attributor.cpp
+++ b/llvm/lib/Transforms/IPO/Attributor.cpp
@@ -2576,23 +2576,23 @@ static bool
identifyAliveSuccessors(Attributor &A, const SwitchInst &SI,
AbstractAttribute &AA,
SmallVectorImpl<const Instruction *> &AliveSuccessors) {
- bool UsedAssumedInformation = false;
- Optional<ConstantInt *> CI = getAssumedConstant(A, *SI.getCondition(), AA);
+ Optional<ConstantInt *> CI = getAssumedConstant(A, *SI.getCondition(), AA);
if (!CI.hasValue()) {
// No value yet, assume all edges are dead.
} else if (CI.getValue()) {
for (auto &CaseIt : SI.cases()) {
if (CaseIt.getCaseValue() == CI.getValue()) {
AliveSuccessors.push_back(&CaseIt.getCaseSuccessor()->front());
- UsedAssumedInformation = true;
- break;
+ return true;
}
}
+ AliveSuccessors.push_back(&SI.getDefaultDest()->front());
+ return true;
} else {
for (const BasicBlock *SuccBB : successors(SI.getParent()))
AliveSuccessors.push_back(&SuccBB->front());
}
- return UsedAssumedInformation;
+ return false;
}
ChangeStatus AAIsDeadFunction::updateImpl(Attributor &A) {
diff --git a/llvm/test/Transforms/FunctionAttrs/liveness.ll b/llvm/test/Transforms/FunctionAttrs/liveness.ll
index 85afb10ca08f..2526d65bbf52 100644
--- a/llvm/test/Transforms/FunctionAttrs/liveness.ll
+++ b/llvm/test/Transforms/FunctionAttrs/liveness.ll
@@ -1,5 +1,6 @@
-; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
+; NOTE: Assertions have been autogenerated by utils/update_test_checks.py UTC_ARGS: --function-signature --scrub-attributes
; RUN: opt -attributor --attributor-disable=false -attributor-max-iterations-verify -attributor-annotate-decl-cs -attributor-max-iterations=6 -S < %s | FileCheck %s
+; UTC_ARGS: --turn off
declare void @no_return_call() nofree noreturn nounwind readnone
@@ -748,3 +749,43 @@ define void @useless_arg_ext_int_ext(i32* %a) {
call void @useless_arg_ext_int(i32* %a)
ret void
}
+
+; UTC_ARGS: --turn on
+
+; FIXME: We should fold terminators.
+
+define internal i32 @switch_default(i64 %i) nounwind {
+; CHECK-LABEL: define {{[^@]+}}@switch_default
+; CHECK-SAME: (i64 [[I:%.*]])
+; CHECK-NEXT: entry:
+; CHECK-NEXT: switch i64 0, label [[SW_DEFAULT:%.*]] [
+; CHECK-NEXT: i64 3, label [[RETURN:%.*]]
+; CHECK-NEXT: i64 10, label [[RETURN]]
+; CHECK-NEXT: ]
+; CHECK: sw.default:
+; CHECK-NEXT: ret i32 123
+; CHECK: return:
+; CHECK-NEXT: unreachable
+;
+entry:
+ switch i64 %i, label %sw.default [
+ i64 3, label %return
+ i64 10, label %return
+ ]
+
+sw.default:
+ ret i32 123
+
+return:
+ ret i32 0
+}
+
+define i32 @switch_default_caller() {
+; CHECK-LABEL: define {{[^@]+}}@switch_default_caller()
+; CHECK-NEXT: [[CALL2:%.*]] = tail call i32 @switch_default(i64 0)
+; CHECK-NEXT: ret i32 123
+;
+ %call2 = tail call i32 @switch_default(i64 0)
+ ret i32 %call2
+}
+; UTC_ARGS: --turn off
More information about the llvm-commits
mailing list