[PATCH] D71568: [InstCombine] `select + mul` -> `select + shl` with power of twos.

Sanjay Patel via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Wed Jan 22 13:01:07 PST 2020


spatel added a comment.

I'm struggling to keep all of the poison potential straight. Can we make this patch only include foldMulPow2Cst() (remove foldMulShl())?

Double-check to make sure I've translated this correctly:

  define i32 @shift_if_power2_double_select_zext(i32 %x, i32 %y, i1 %cond1, i1 %cond2) {
    %shl = shl nsw i32 2147483648, %y
    %sel1 = select i1 %cond1, i32 %shl, i32 1024
    %sel2 = select i1 %cond2, i32 16, i32 %sel1
    %r = mul nsw i32 %x, %sel2
    ret i32 %r
  }
  
  $ opt -instcombine mul.ll -S
  
  define i32 @shift_if_power2_double_select_zext(i32 %x, i32 %y, i1 %cond1, i1 %cond2) {
    %1 = add i32 %y, 31
    %.v = select i1 %cond1, i32 %1, i32 10
    %r.v = select i1 %cond2, i32 4, i32 %.v
    %r = shl nsw i32 %x, %r.v
    ret i32 %r
  }

Miscompile?
https://rise4fun.com/Alive/YcG


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D71568/new/

https://reviews.llvm.org/D71568





More information about the llvm-commits mailing list