aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/validation/optim/void-if-convert.c
diff options
authorLuc Van Oostenryck <luc.vanoostenryck@gmail.com>2017-04-24 05:48:00 +0200
committerLuc Van Oostenryck <luc.vanoostenryck@gmail.com>2017-05-12 00:31:26 +0200
commit3c223f5d367f4db2c2f828ee79dd5b93de63f39d (patch)
treed286e73e1dcdafb9c42d6891a9843de5dd22c7d5 /validation/optim/void-if-convert.c
parente35efe330c6ae7d154197c29b127560d569016d0 (diff)
downloadsparse-dev-3c223f5d367f4db2c2f828ee79dd5b93de63f39d.tar.gz
ignore VOID when trying to if-convert phi-nodes
Simple if-then-else expressions can often be replaced by an OP_SELECT. This is done in a very generic way by looking not at the test/if part but at OP_PHIs which contain exactly 2 values. An implementation detail makes that the address of valid OP_PHI's sources must not change, so the list holding these values must not be repacked and such. As consequence, when a value need to be removed from the list this value is simply replaced in the list by a VOID. These VOIDs must then be ignored when processing OP_PHI's sources. But for the if-conversion, these VOID are not ignored and are thus considered like any other value which in turn make miss some optimization opportunities. For example code like: int foo(int a) { if (a) return 0; else return 1; return 2; } will be linearized into something like: ... phi.32 %r2 <- %phi1, %phi2, VOID ret.32 %r2 where %phi1 & %phi2 correspond to the 'return 0' & 'return 1' and the VOID correspond to the dead 'return 2'. This code should be trivially be converted to a select but is not because the OP_PHI is considered as having 3 elements instead of 2. Worse, if at some moment we would have a phi list with: phi.32 %r2 <- %phi1, VOID then the optimization would trigger but the corresponding code make the assumption that the pseudos are the target of an OP_PHISOURCE instruction, which VOIDs, of course, are not and a crash should ensue. Fix this by filtering out these VOIDs before checking the conditions of the if-conversion. Signed-off-by: Luc Van Oostenryck <luc.vanoostenryck@gmail.com>
Diffstat (limited to 'validation/optim/void-if-convert.c')
-rw-r--r--validation/optim/void-if-convert.c19
1 files changed, 19 insertions, 0 deletions
diff --git a/validation/optim/void-if-convert.c b/validation/optim/void-if-convert.c
new file mode 100644
index 00000000..66513c4d
--- /dev/null
+++ b/validation/optim/void-if-convert.c
@@ -0,0 +1,19 @@
+int foo(int a)
+{
+ if (a)
+ return 0;
+ else
+ return 1;
+ return 2;
+}
+
+/*
+ * check-name: Ignore VOID in if-convert
+ * check-command: test-linearize -Wno-decl $file
+ * check-output-ignore
+ *
+ * check-output-excludes: phisrc\\.
+ * check-output-excludes: phi\\.
+ * check-output-excludes: VOID
+ * check-output-contains: seteq\\.
+ */