[PATCH] Fix GlobalOpt to use range metadata instead of creating SelectInsts.

Rafael EspĂ­ndola rafael.espindola at gmail.com
Wed Mar 12 06:38:53 PDT 2014


+      Constant *Cmp = ConstantExpr::getICmp(ICmpInst::ICMP_SLT,
InitVal, OtherVal);
+      Constant *One = ConstantInt::get(LI->getType(), 1);
+      Value *Vals[] = {
+        ConstantExpr::getSelect(Cmp, InitVal, OtherVal),
+        ConstantExpr::getAdd(ConstantExpr::getSelect(Cmp, OtherVal,
InitVal), One)
+      };
+      MDNode *MD = MDNode::get(LI->getContext(), Vals);

This is assuming the comparisons folds. It would probably be a bit
nicer to work with the integer values directly.

The comment

;; check that global opt turns integers that only hold 0 or 1 into bools

is now out of date.

The new optimization is a bit simpler and a bit less likely to upset
other optimizations, but it is also a bit less powerful. Can you
explain why you want the change? Have you hit a case where the select
was detrimental?

Cheers,
Rafael



More information about the llvm-commits mailing list