[PATCH] D20275: [SimplifyCFG] eliminate switch cases based on known range of switch condition
Sanjay Patel via llvm-commits
llvm-commits at lists.llvm.org
Fri May 20 07:59:40 PDT 2016
This revision was automatically updated to reflect the committed changes.
Closed by commit rL270222: [SimplifyCFG] eliminate switch cases based on known range of switch condition (authored by spatel).
Changed prior to commit:
http://reviews.llvm.org/D20275?vs=57856&id=57933#toc
Repository:
rL LLVM
http://reviews.llvm.org/D20275
Files:
llvm/trunk/lib/Transforms/Utils/SimplifyCFG.cpp
llvm/trunk/test/Transforms/SimplifyCFG/switch-masked-bits.ll
Index: llvm/trunk/lib/Transforms/Utils/SimplifyCFG.cpp
===================================================================
--- llvm/trunk/lib/Transforms/Utils/SimplifyCFG.cpp
+++ llvm/trunk/lib/Transforms/Utils/SimplifyCFG.cpp
@@ -3914,14 +3914,20 @@
APInt KnownZero(Bits, 0), KnownOne(Bits, 0);
computeKnownBits(Cond, KnownZero, KnownOne, DL, 0, AC, SI);
+ // We can also eliminate cases by determining that their values are outside of
+ // the limited range of the condition based on how many significant (non-sign)
+ // bits are in the condition value.
+ unsigned ExtraSignBits = ComputeNumSignBits(Cond, DL, 0, AC, SI) - 1;
+ unsigned MaxSignificantBitsInCond = Bits - ExtraSignBits;
+
// Gather dead cases.
SmallVector<ConstantInt *, 8> DeadCases;
for (auto &Case : SI->cases()) {
- if ((Case.getCaseValue()->getValue() & KnownZero) != 0 ||
- (Case.getCaseValue()->getValue() & KnownOne) != KnownOne) {
+ APInt CaseVal = Case.getCaseValue()->getValue();
+ if ((CaseVal & KnownZero) != 0 || (CaseVal & KnownOne) != KnownOne ||
+ (CaseVal.getMinSignedBits() > MaxSignificantBitsInCond)) {
DeadCases.push_back(Case.getCaseValue());
- DEBUG(dbgs() << "SimplifyCFG: switch case '" << Case.getCaseValue()
- << "' is dead.\n");
+ DEBUG(dbgs() << "SimplifyCFG: switch case " << CaseVal << " is dead.\n");
}
}
Index: llvm/trunk/test/Transforms/SimplifyCFG/switch-masked-bits.ll
===================================================================
--- llvm/trunk/test/Transforms/SimplifyCFG/switch-masked-bits.ll
+++ llvm/trunk/test/Transforms/SimplifyCFG/switch-masked-bits.ll
@@ -49,14 +49,10 @@
define i1 @repeated_signbits(i8 %condition) {
; CHECK-LABEL: @repeated_signbits(
; CHECK: switch i32
-; CHECK-DAG: i32 -2147483648, label %a
-; CHECK-DAG: i32 -129, label %a
; CHECK-DAG: i32 -128, label %a
; CHECK-DAG: i32 -1, label %a
; CHECK-DAG: i32 0, label %a
; CHECK-DAG: i32 127, label %a
-; CHECK-DAG: i32 128, label %a
-; CHECK-DAG: i32 2147483647, label %a
; CHECK-NEXT: ]
;
entry:
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D20275.57933.patch
Type: text/x-patch
Size: 2131 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20160520/aff5b930/attachment.bin>
More information about the llvm-commits
mailing list